Skip to content

Commit bcb5503

Browse files
authored
fix: remove Blob usage (#1384)
* fix: remove `Blob` usage
1 parent b276ec1 commit bcb5503

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: packages/fetch-http-handler/src/stream-collector.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { fromBase64 } from "@aws-sdk/util-base64-browser";
33

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

10-
return collectStream(stream);
10+
return collectStream(stream as ReadableStream);
1111
};
1212

1313
async function collectBlob(blob: Blob): Promise<Uint8Array> {

Diff for: packages/util-body-length-browser/src/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
export function calculateBodyLength(body: any): number | undefined {
22
if (typeof body === "string") {
3-
return new Blob([body]).size;
3+
let len = body.length;
4+
5+
for (let i = len - 1; i >= 0; i--) {
6+
const code = body.charCodeAt(i);
7+
if (code > 0x7f && code <= 0x7ff) len++;
8+
else if (code > 0x7ff && code <= 0xffff) len += 2;
9+
}
10+
11+
return len;
412
} else if (typeof body.byteLength === "number") {
513
// handles Uint8Array, ArrayBuffer, Buffer, and ArrayBufferView
614
return body.byteLength;

0 commit comments

Comments
 (0)