Skip to content

Commit

Permalink
fix: remove Blob usage (#1384)
Browse files Browse the repository at this point in the history
* fix: remove `Blob` usage
  • Loading branch information
blakeembrey authored Jul 20, 2020
1 parent b276ec1 commit bcb5503
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/fetch-http-handler/src/stream-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { fromBase64 } from "@aws-sdk/util-base64-browser";

//reference: https://snack.expo.io/r1JCSWRGU
export const streamCollector: StreamCollector = (stream: Blob | ReadableStream): Promise<Uint8Array> => {
if (stream instanceof Blob) {
if (typeof Blob === "function" && stream instanceof Blob) {
return collectBlob(stream);
}

return collectStream(stream);
return collectStream(stream as ReadableStream);
};

async function collectBlob(blob: Blob): Promise<Uint8Array> {
Expand Down
10 changes: 9 additions & 1 deletion packages/util-body-length-browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
export function calculateBodyLength(body: any): number | undefined {
if (typeof body === "string") {
return new Blob([body]).size;
let len = body.length;

for (let i = len - 1; i >= 0; i--) {
const code = body.charCodeAt(i);
if (code > 0x7f && code <= 0x7ff) len++;
else if (code > 0x7ff && code <= 0xffff) len += 2;
}

return len;
} else if (typeof body.byteLength === "number") {
// handles Uint8Array, ArrayBuffer, Buffer, and ArrayBufferView
return body.byteLength;
Expand Down

0 comments on commit bcb5503

Please sign in to comment.