Skip to content

Commit

Permalink
fix: use Response.arrayBuffer() in replace of FileReader
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Jan 13, 2020
1 parent 72271ca commit a81e50a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/fetch-http-handler/src/fetch-http-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("httpHandler", () => {
["bizz", "bazz"]
])
},
blob: jest.fn().mockResolvedValue("")
body: "FOO" //should be a ReadableStream in real life.
};
const mockFetch = jest.fn().mockResolvedValue(mockResponse);

Expand All @@ -50,7 +50,7 @@ describe("httpHandler", () => {
let response = await fetchHttpHandler.handle({} as any, {});

expect(mockFetch.mock.calls.length).toBe(1);
expect(mockResponse.blob.mock.calls.length).toBe(1);
expect(response.response.body).toBe("FOO");
});

it("properly constructs url", async () => {
Expand All @@ -61,7 +61,7 @@ describe("httpHandler", () => {
["bizz", "bazz"]
])
},
blob: jest.fn().mockResolvedValue("")
body: ""
};
const mockFetch = jest.fn().mockResolvedValue(mockResponse);

Expand Down
13 changes: 3 additions & 10 deletions packages/stream-collector-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import { StreamCollector } from "@aws-sdk/types";
export const streamCollector: StreamCollector = (
stream: ReadableStream
): Promise<Uint8Array> => {
const blobToArrayBuffer = (stream: Blob) =>
new Promise<Uint8Array>((resolve, reject) => {
const reader = new FileReader();
reader.onload = () =>
resolve(new Uint8Array(reader.result as ArrayBuffer));
reader.onabort = () => reject(new Error("Read aborted"));
reader.onerror = () => reject(reader.error);
reader.readAsArrayBuffer(stream);
});
return new Response(stream).blob().then(blobToArrayBuffer);
return new Response(stream)
.arrayBuffer()
.then(arrayBuffer => new Uint8Array(arrayBuffer));
};

0 comments on commit a81e50a

Please sign in to comment.