@aws-sdk/util-stream-browser
Advanced tools
Comparing version 3.183.0 to 3.186.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06) | ||
**Note:** Version bump only for package @aws-sdk/util-stream-browser | ||
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03) | ||
@@ -8,0 +16,0 @@ |
@@ -1,4 +0,5 @@ | ||
export const getAwsChunkedEncodingStream = (readableStream, options) => { | ||
const { base64Encoder, bodyLengthChecker, checksumAlgorithmFn, checksumLocationName, streamHasher } = options; | ||
const checksumRequired = base64Encoder !== undefined && | ||
import { __awaiter, __generator } from "tslib"; | ||
export var getAwsChunkedEncodingStream = function (readableStream, options) { | ||
var base64Encoder = options.base64Encoder, bodyLengthChecker = options.bodyLengthChecker, checksumAlgorithmFn = options.checksumAlgorithmFn, checksumLocationName = options.checksumLocationName, streamHasher = options.streamHasher; | ||
var checksumRequired = base64Encoder !== undefined && | ||
bodyLengthChecker !== undefined && | ||
@@ -8,21 +9,35 @@ checksumAlgorithmFn !== undefined && | ||
streamHasher !== undefined; | ||
const digest = checksumRequired ? streamHasher(checksumAlgorithmFn, readableStream) : undefined; | ||
const reader = readableStream.getReader(); | ||
var digest = checksumRequired ? streamHasher(checksumAlgorithmFn, readableStream) : undefined; | ||
var reader = readableStream.getReader(); | ||
return new ReadableStream({ | ||
async pull(controller) { | ||
const { value, done } = await reader.read(); | ||
if (done) { | ||
controller.enqueue(`0\r\n`); | ||
if (checksumRequired) { | ||
const checksum = base64Encoder(await digest); | ||
controller.enqueue(`${checksumLocationName}:${checksum}\r\n`); | ||
controller.enqueue(`\r\n`); | ||
} | ||
controller.close(); | ||
} | ||
else { | ||
controller.enqueue(`${(bodyLengthChecker(value) || 0).toString(16)}\r\n${value}\r\n`); | ||
} | ||
pull: function (controller) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, value, done, checksum, _b; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: return [4, reader.read()]; | ||
case 1: | ||
_a = _c.sent(), value = _a.value, done = _a.done; | ||
if (!done) return [3, 4]; | ||
controller.enqueue("0\r\n"); | ||
if (!checksumRequired) return [3, 3]; | ||
_b = base64Encoder; | ||
return [4, digest]; | ||
case 2: | ||
checksum = _b.apply(void 0, [_c.sent()]); | ||
controller.enqueue("".concat(checksumLocationName, ":").concat(checksum, "\r\n")); | ||
controller.enqueue("\r\n"); | ||
_c.label = 3; | ||
case 3: | ||
controller.close(); | ||
return [3, 5]; | ||
case 4: | ||
controller.enqueue("".concat((bodyLengthChecker(value) || 0).toString(16), "\r\n").concat(value, "\r\n")); | ||
_c.label = 5; | ||
case 5: return [2]; | ||
} | ||
}); | ||
}); | ||
}, | ||
}); | ||
}; |
@@ -0,1 +1,2 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { streamCollector } from "@aws-sdk/fetch-http-handler"; | ||
@@ -5,17 +6,24 @@ import { toBase64 } from "@aws-sdk/util-base64-browser"; | ||
import { toUtf8 } from "@aws-sdk/util-utf8-browser"; | ||
const ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED = "The stream has already been transformed."; | ||
export const sdkStreamMixin = (stream) => { | ||
var ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED = "The stream has already been transformed."; | ||
export var sdkStreamMixin = function (stream) { | ||
var _a, _b; | ||
if (!isBlobInstance(stream) && !isReadableStreamInstance(stream)) { | ||
const name = stream?.__proto__?.constructor?.name || stream; | ||
throw new Error(`Unexpected stream implementation, expect Blob or ReadableStream, got ${name}`); | ||
var name_1 = ((_b = (_a = stream === null || stream === void 0 ? void 0 : stream.__proto__) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name) || stream; | ||
throw new Error("Unexpected stream implementation, expect Blob or ReadableStream, got ".concat(name_1)); | ||
} | ||
let transformed = false; | ||
const transformToByteArray = async () => { | ||
if (transformed) { | ||
throw new Error(ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED); | ||
} | ||
transformed = true; | ||
return await streamCollector(stream); | ||
}; | ||
const blobToWebStream = (blob) => { | ||
var transformed = false; | ||
var transformToByteArray = function () { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (transformed) { | ||
throw new Error(ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED); | ||
} | ||
transformed = true; | ||
return [4, streamCollector(stream)]; | ||
case 1: return [2, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
var blobToWebStream = function (blob) { | ||
if (typeof blob.stream !== "function") { | ||
@@ -29,21 +37,29 @@ throw new Error("Cannot transform payload Blob to web stream. Please make sure the Blob.stream() is polyfilled.\n" + | ||
transformToByteArray: transformToByteArray, | ||
transformToString: async (encoding) => { | ||
const buf = await transformToByteArray(); | ||
if (encoding === "base64") { | ||
return toBase64(buf); | ||
} | ||
else if (encoding === "hex") { | ||
return toHex(buf); | ||
} | ||
else if (encoding === undefined || encoding === "utf8" || encoding === "utf-8") { | ||
return toUtf8(buf); | ||
} | ||
else if (typeof TextDecoder === "function") { | ||
return new TextDecoder(encoding).decode(buf); | ||
} | ||
else { | ||
throw new Error("TextDecoder is not available, please make sure polyfill is provided."); | ||
} | ||
}, | ||
transformToWebStream: () => { | ||
transformToString: function (encoding) { return __awaiter(void 0, void 0, void 0, function () { | ||
var buf; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, transformToByteArray()]; | ||
case 1: | ||
buf = _a.sent(); | ||
if (encoding === "base64") { | ||
return [2, toBase64(buf)]; | ||
} | ||
else if (encoding === "hex") { | ||
return [2, toHex(buf)]; | ||
} | ||
else if (encoding === undefined || encoding === "utf8" || encoding === "utf-8") { | ||
return [2, toUtf8(buf)]; | ||
} | ||
else if (typeof TextDecoder === "function") { | ||
return [2, new TextDecoder(encoding).decode(buf)]; | ||
} | ||
else { | ||
throw new Error("TextDecoder is not available, please make sure polyfill is provided."); | ||
} | ||
return [2]; | ||
} | ||
}); | ||
}); }, | ||
transformToWebStream: function () { | ||
if (transformed) { | ||
@@ -60,3 +76,3 @@ throw new Error(ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED); | ||
else { | ||
throw new Error(`Cannot transform payload to web stream, got ${stream}`); | ||
throw new Error("Cannot transform payload to web stream, got ".concat(stream)); | ||
} | ||
@@ -66,3 +82,5 @@ }, | ||
}; | ||
const isBlobInstance = (stream) => typeof Blob === "function" && stream instanceof Blob; | ||
const isReadableStreamInstance = (stream) => typeof ReadableStream === "function" && stream instanceof ReadableStream; | ||
var isBlobInstance = function (stream) { return typeof Blob === "function" && stream instanceof Blob; }; | ||
var isReadableStreamInstance = function (stream) { | ||
return typeof ReadableStream === "function" && stream instanceof ReadableStream; | ||
}; |
{ | ||
"name": "@aws-sdk/util-stream-browser", | ||
"version": "3.183.0", | ||
"version": "3.186.0", | ||
"scripts": { | ||
@@ -22,7 +22,7 @@ "build": "concurrently 'yarn:build:es' 'yarn:build:types'", | ||
"dependencies": { | ||
"@aws-sdk/fetch-http-handler": "3.183.0", | ||
"@aws-sdk/types": "3.183.0", | ||
"@aws-sdk/util-base64-browser": "3.183.0", | ||
"@aws-sdk/util-hex-encoding": "3.183.0", | ||
"@aws-sdk/util-utf8-browser": "3.183.0", | ||
"@aws-sdk/fetch-http-handler": "3.186.0", | ||
"@aws-sdk/types": "3.186.0", | ||
"@aws-sdk/util-base64-browser": "3.186.0", | ||
"@aws-sdk/util-hex-encoding": "3.186.0", | ||
"@aws-sdk/util-utf8-browser": "3.186.0", | ||
"tslib": "^2.3.1" | ||
@@ -29,0 +29,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24469
145
+ Added@aws-sdk/fetch-http-handler@3.186.0(transitive)
+ Added@aws-sdk/protocol-http@3.186.0(transitive)
+ Added@aws-sdk/querystring-builder@3.186.0(transitive)
+ Added@aws-sdk/types@3.186.0(transitive)
+ Added@aws-sdk/util-base64-browser@3.186.0(transitive)
+ Added@aws-sdk/util-hex-encoding@3.186.0(transitive)
+ Added@aws-sdk/util-uri-escape@3.186.0(transitive)
+ Added@aws-sdk/util-utf8-browser@3.186.0(transitive)
- Removed@aws-sdk/fetch-http-handler@3.183.0(transitive)
- Removed@aws-sdk/protocol-http@3.183.0(transitive)
- Removed@aws-sdk/querystring-builder@3.183.0(transitive)
- Removed@aws-sdk/types@3.183.0(transitive)
- Removed@aws-sdk/util-base64-browser@3.183.0(transitive)
- Removed@aws-sdk/util-hex-encoding@3.183.0(transitive)
- Removed@aws-sdk/util-uri-escape@3.183.0(transitive)
- Removed@aws-sdk/util-utf8-browser@3.183.0(transitive)
Updated@aws-sdk/types@3.186.0