@smithy/util-stream
Advanced tools
@@ -5,6 +5,7 @@ "use strict"; | ||
| class ByteArrayCollector { | ||
| allocByteArray; | ||
| byteLength = 0; | ||
| byteArrays = []; | ||
| constructor(allocByteArray) { | ||
| this.allocByteArray = allocByteArray; | ||
| this.byteLength = 0; | ||
| this.byteArrays = []; | ||
| } | ||
@@ -11,0 +12,0 @@ push(byteArray) { |
@@ -7,4 +7,8 @@ "use strict"; | ||
| class ChecksumStream extends stream_1.Duplex { | ||
| expectedChecksum; | ||
| checksumSourceLocation; | ||
| checksum; | ||
| source; | ||
| base64Encoder; | ||
| constructor({ expectedChecksum, checksum, source, checksumSourceLocation, base64Encoder, }) { | ||
| var _a, _b; | ||
| super(); | ||
@@ -15,5 +19,5 @@ if (typeof source.pipe === "function") { | ||
| else { | ||
| throw new Error(`@smithy/util-stream: unsupported source type ${(_b = (_a = source === null || source === void 0 ? void 0 : source.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : source} in ChecksumStream.`); | ||
| throw new Error(`@smithy/util-stream: unsupported source type ${source?.constructor?.name ?? source} in ChecksumStream.`); | ||
| } | ||
| this.base64Encoder = base64Encoder !== null && base64Encoder !== void 0 ? base64Encoder : util_base64_1.toBase64; | ||
| this.base64Encoder = base64Encoder ?? util_base64_1.toBase64; | ||
| this.expectedChecksum = expectedChecksum; | ||
@@ -20,0 +24,0 @@ this.checksum = checksum; |
@@ -8,7 +8,6 @@ "use strict"; | ||
| const createChecksumStream = ({ expectedChecksum, checksum, source, checksumSourceLocation, base64Encoder, }) => { | ||
| var _a, _b; | ||
| if (!(0, stream_type_check_1.isReadableStream)(source)) { | ||
| throw new Error(`@smithy/util-stream: unsupported source type ${(_b = (_a = source === null || source === void 0 ? void 0 : source.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : source} in ChecksumStream.`); | ||
| throw new Error(`@smithy/util-stream: unsupported source type ${source?.constructor?.name ?? source} in ChecksumStream.`); | ||
| } | ||
| const encoder = base64Encoder !== null && base64Encoder !== void 0 ? base64Encoder : util_base64_1.toBase64; | ||
| const encoder = base64Encoder ?? util_base64_1.toBase64; | ||
| if (typeof TransformStream !== "function") { | ||
@@ -15,0 +14,0 @@ throw new Error("@smithy/util-stream: unable to instantiate ChecksumStream because API unavailable: ReadableStream/TransformStream."); |
@@ -43,3 +43,3 @@ "use strict"; | ||
| streamBufferingLoggedWarning = true; | ||
| logger === null || logger === void 0 ? void 0 : logger.warn(`@smithy/util-stream - stream chunk size ${chunkSize} is below threshold of ${size}, automatically buffering.`); | ||
| logger?.warn(`@smithy/util-stream - stream chunk size ${chunkSize} is below threshold of ${size}, automatically buffering.`); | ||
| } | ||
@@ -46,0 +46,0 @@ if (newSize >= size) { |
@@ -50,3 +50,3 @@ "use strict"; | ||
| streamBufferingLoggedWarning = true; | ||
| logger === null || logger === void 0 ? void 0 : logger.warn(`@smithy/util-stream - stream chunk size ${chunkSize} is below threshold of ${size}, automatically buffering.`); | ||
| logger?.warn(`@smithy/util-stream - stream chunk size ${chunkSize} is below threshold of ${size}, automatically buffering.`); | ||
| } | ||
@@ -91,4 +91,3 @@ if (newSize >= size) { | ||
| function sizeOf(chunk) { | ||
| var _a, _b; | ||
| return (_b = (_a = chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) !== null && _a !== void 0 ? _a : chunk === null || chunk === void 0 ? void 0 : chunk.length) !== null && _b !== void 0 ? _b : 0; | ||
| return chunk?.byteLength ?? chunk?.length ?? 0; | ||
| } | ||
@@ -95,0 +94,0 @@ function modeOf(chunk, allowBuffer = true) { |
@@ -5,3 +5,2 @@ "use strict"; | ||
| async function headStream(stream, bytes) { | ||
| var _a; | ||
| let byteLengthCounter = 0; | ||
@@ -15,3 +14,3 @@ const chunks = []; | ||
| chunks.push(value); | ||
| byteLengthCounter += (_a = value === null || value === void 0 ? void 0 : value.byteLength) !== null && _a !== void 0 ? _a : 0; | ||
| byteLengthCounter += value?.byteLength ?? 0; | ||
| } | ||
@@ -18,0 +17,0 @@ if (byteLengthCounter >= bytes) { |
@@ -28,12 +28,8 @@ "use strict"; | ||
| class Collector extends stream_1.Writable { | ||
| constructor() { | ||
| super(...arguments); | ||
| this.buffers = []; | ||
| this.limit = Infinity; | ||
| this.bytesBuffered = 0; | ||
| } | ||
| buffers = []; | ||
| limit = Infinity; | ||
| bytesBuffered = 0; | ||
| _write(chunk, encoding, callback) { | ||
| var _a; | ||
| this.buffers.push(chunk); | ||
| this.bytesBuffered += (_a = chunk.byteLength) !== null && _a !== void 0 ? _a : 0; | ||
| this.bytesBuffered += chunk.byteLength ?? 0; | ||
| if (this.bytesBuffered >= this.limit) { | ||
@@ -40,0 +36,0 @@ const excess = this.bytesBuffered - this.limit; |
+83
-93
@@ -1,103 +0,93 @@ | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| 'use strict'; | ||
| // src/index.ts | ||
| var index_exports = {}; | ||
| __export(index_exports, { | ||
| Uint8ArrayBlobAdapter: () => Uint8ArrayBlobAdapter | ||
| }); | ||
| module.exports = __toCommonJS(index_exports); | ||
| var utilBase64 = require('@smithy/util-base64'); | ||
| var utilUtf8 = require('@smithy/util-utf8'); | ||
| var ChecksumStream = require('./checksum/ChecksumStream'); | ||
| var createChecksumStream = require('./checksum/createChecksumStream'); | ||
| var createBufferedReadable = require('./createBufferedReadable'); | ||
| var getAwsChunkedEncodingStream = require('./getAwsChunkedEncodingStream'); | ||
| var headStream = require('./headStream'); | ||
| var sdkStreamMixin = require('./sdk-stream-mixin'); | ||
| var splitStream = require('./splitStream'); | ||
| var streamTypeCheck = require('./stream-type-check'); | ||
| // src/blob/transforms.ts | ||
| var import_util_base64 = require("@smithy/util-base64"); | ||
| var import_util_utf8 = require("@smithy/util-utf8"); | ||
| function transformToString(payload, encoding = "utf-8") { | ||
| if (encoding === "base64") { | ||
| return (0, import_util_base64.toBase64)(payload); | ||
| } | ||
| return (0, import_util_utf8.toUtf8)(payload); | ||
| if (encoding === "base64") { | ||
| return utilBase64.toBase64(payload); | ||
| } | ||
| return utilUtf8.toUtf8(payload); | ||
| } | ||
| __name(transformToString, "transformToString"); | ||
| function transformFromString(str, encoding) { | ||
| if (encoding === "base64") { | ||
| return Uint8ArrayBlobAdapter.mutate((0, import_util_base64.fromBase64)(str)); | ||
| } | ||
| return Uint8ArrayBlobAdapter.mutate((0, import_util_utf8.fromUtf8)(str)); | ||
| if (encoding === "base64") { | ||
| return Uint8ArrayBlobAdapter.mutate(utilBase64.fromBase64(str)); | ||
| } | ||
| return Uint8ArrayBlobAdapter.mutate(utilUtf8.fromUtf8(str)); | ||
| } | ||
| __name(transformFromString, "transformFromString"); | ||
| // src/blob/Uint8ArrayBlobAdapter.ts | ||
| var Uint8ArrayBlobAdapter = class _Uint8ArrayBlobAdapter extends Uint8Array { | ||
| static { | ||
| __name(this, "Uint8ArrayBlobAdapter"); | ||
| } | ||
| /** | ||
| * @param source - such as a string or Stream. | ||
| * @returns a new Uint8ArrayBlobAdapter extending Uint8Array. | ||
| */ | ||
| static fromString(source, encoding = "utf-8") { | ||
| switch (typeof source) { | ||
| case "string": | ||
| return transformFromString(source, encoding); | ||
| default: | ||
| throw new Error(`Unsupported conversion from ${typeof source} to Uint8ArrayBlobAdapter.`); | ||
| class Uint8ArrayBlobAdapter extends Uint8Array { | ||
| static fromString(source, encoding = "utf-8") { | ||
| switch (typeof source) { | ||
| case "string": | ||
| return transformFromString(source, encoding); | ||
| default: | ||
| throw new Error(`Unsupported conversion from ${typeof source} to Uint8ArrayBlobAdapter.`); | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * @param source - Uint8Array to be mutated. | ||
| * @returns the same Uint8Array but with prototype switched to Uint8ArrayBlobAdapter. | ||
| */ | ||
| static mutate(source) { | ||
| Object.setPrototypeOf(source, _Uint8ArrayBlobAdapter.prototype); | ||
| return source; | ||
| } | ||
| /** | ||
| * @param encoding - default 'utf-8'. | ||
| * @returns the blob as string. | ||
| */ | ||
| transformToString(encoding = "utf-8") { | ||
| return transformToString(this, encoding); | ||
| } | ||
| }; | ||
| static mutate(source) { | ||
| Object.setPrototypeOf(source, Uint8ArrayBlobAdapter.prototype); | ||
| return source; | ||
| } | ||
| transformToString(encoding = "utf-8") { | ||
| return transformToString(this, encoding); | ||
| } | ||
| } | ||
| // src/index.ts | ||
| __reExport(index_exports, require("./checksum/ChecksumStream"), module.exports); | ||
| __reExport(index_exports, require("./checksum/createChecksumStream"), module.exports); | ||
| __reExport(index_exports, require("././createBufferedReadable"), module.exports); | ||
| __reExport(index_exports, require("././getAwsChunkedEncodingStream"), module.exports); | ||
| __reExport(index_exports, require("././headStream"), module.exports); | ||
| __reExport(index_exports, require("././sdk-stream-mixin"), module.exports); | ||
| __reExport(index_exports, require("././splitStream"), module.exports); | ||
| __reExport(index_exports, require("././stream-type-check"), module.exports); | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Uint8ArrayBlobAdapter, | ||
| ChecksumStream, | ||
| createChecksumStream, | ||
| createBufferedReadable, | ||
| getAwsChunkedEncodingStream, | ||
| headStream, | ||
| sdkStreamMixin, | ||
| splitStream, | ||
| isReadableStream, | ||
| isBlob | ||
| exports.Uint8ArrayBlobAdapter = Uint8ArrayBlobAdapter; | ||
| Object.keys(ChecksumStream).forEach(function (k) { | ||
| if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { | ||
| enumerable: true, | ||
| get: function () { return ChecksumStream[k]; } | ||
| }); | ||
| }); | ||
| Object.keys(createChecksumStream).forEach(function (k) { | ||
| if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { | ||
| enumerable: true, | ||
| get: function () { return createChecksumStream[k]; } | ||
| }); | ||
| }); | ||
| Object.keys(createBufferedReadable).forEach(function (k) { | ||
| if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { | ||
| enumerable: true, | ||
| get: function () { return createBufferedReadable[k]; } | ||
| }); | ||
| }); | ||
| Object.keys(getAwsChunkedEncodingStream).forEach(function (k) { | ||
| if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { | ||
| enumerable: true, | ||
| get: function () { return getAwsChunkedEncodingStream[k]; } | ||
| }); | ||
| }); | ||
| Object.keys(headStream).forEach(function (k) { | ||
| if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { | ||
| enumerable: true, | ||
| get: function () { return headStream[k]; } | ||
| }); | ||
| }); | ||
| Object.keys(sdkStreamMixin).forEach(function (k) { | ||
| if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { | ||
| enumerable: true, | ||
| get: function () { return sdkStreamMixin[k]; } | ||
| }); | ||
| }); | ||
| Object.keys(splitStream).forEach(function (k) { | ||
| if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { | ||
| enumerable: true, | ||
| get: function () { return splitStream[k]; } | ||
| }); | ||
| }); | ||
| Object.keys(streamTypeCheck).forEach(function (k) { | ||
| if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { | ||
| enumerable: true, | ||
| get: function () { return streamTypeCheck[k]; } | ||
| }); | ||
| }); |
@@ -11,5 +11,4 @@ "use strict"; | ||
| const sdkStreamMixin = (stream) => { | ||
| var _a, _b; | ||
| if (!isBlobInstance(stream) && !(0, stream_type_check_1.isReadableStream)(stream)) { | ||
| const name = ((_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; | ||
| const name = stream?.__proto__?.constructor?.name || stream; | ||
| throw new Error(`Unexpected stream implementation, expect Blob or ReadableStream, got ${name}`); | ||
@@ -16,0 +15,0 @@ } |
@@ -10,3 +10,2 @@ "use strict"; | ||
| const sdkStreamMixin = (stream) => { | ||
| var _a, _b; | ||
| if (!(stream instanceof stream_1.Readable)) { | ||
@@ -17,3 +16,3 @@ try { | ||
| catch (e) { | ||
| const name = ((_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; | ||
| const name = stream?.__proto__?.constructor?.name || stream; | ||
| throw new Error(`Unexpected stream implementation, expect Stream.Readable instance, got ${name}`); | ||
@@ -20,0 +19,0 @@ } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isBlob = exports.isReadableStream = void 0; | ||
| const isReadableStream = (stream) => { | ||
| var _a; | ||
| return typeof ReadableStream === "function" && | ||
| (((_a = stream === null || stream === void 0 ? void 0 : stream.constructor) === null || _a === void 0 ? void 0 : _a.name) === ReadableStream.name || stream instanceof ReadableStream); | ||
| }; | ||
| const isReadableStream = (stream) => typeof ReadableStream === "function" && | ||
| (stream?.constructor?.name === ReadableStream.name || stream instanceof ReadableStream); | ||
| exports.isReadableStream = isReadableStream; | ||
| const isBlob = (blob) => { | ||
| var _a; | ||
| return typeof Blob === "function" && (((_a = blob === null || blob === void 0 ? void 0 : blob.constructor) === null || _a === void 0 ? void 0 : _a.name) === Blob.name || blob instanceof Blob); | ||
| return typeof Blob === "function" && (blob?.constructor?.name === Blob.name || blob instanceof Blob); | ||
| }; | ||
| exports.isBlob = isBlob; |
| export class ByteArrayCollector { | ||
| allocByteArray; | ||
| byteLength = 0; | ||
| byteArrays = []; | ||
| constructor(allocByteArray) { | ||
| this.allocByteArray = allocByteArray; | ||
| this.byteLength = 0; | ||
| this.byteArrays = []; | ||
| } | ||
@@ -7,0 +8,0 @@ push(byteArray) { |
| import { toBase64 } from "@smithy/util-base64"; | ||
| import { Duplex } from "stream"; | ||
| export class ChecksumStream extends Duplex { | ||
| expectedChecksum; | ||
| checksumSourceLocation; | ||
| checksum; | ||
| source; | ||
| base64Encoder; | ||
| constructor({ expectedChecksum, checksum, source, checksumSourceLocation, base64Encoder, }) { | ||
@@ -5,0 +10,0 @@ super(); |
@@ -24,8 +24,5 @@ import { Writable } from "stream"; | ||
| class Collector extends Writable { | ||
| constructor() { | ||
| super(...arguments); | ||
| this.buffers = []; | ||
| this.limit = Infinity; | ||
| this.bytesBuffered = 0; | ||
| } | ||
| buffers = []; | ||
| limit = Infinity; | ||
| bytesBuffered = 0; | ||
| _write(chunk, encoding, callback) { | ||
@@ -32,0 +29,0 @@ this.buffers.push(chunk); |
+8
-8
| { | ||
| "name": "@smithy/util-stream", | ||
| "version": "4.3.2", | ||
| "version": "4.4.0", | ||
| "scripts": { | ||
@@ -32,9 +32,9 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'", | ||
| "dependencies": { | ||
| "@smithy/fetch-http-handler": "^5.2.1", | ||
| "@smithy/node-http-handler": "^4.2.1", | ||
| "@smithy/types": "^4.5.0", | ||
| "@smithy/util-base64": "^4.1.0", | ||
| "@smithy/util-buffer-from": "^4.1.0", | ||
| "@smithy/util-hex-encoding": "^4.1.0", | ||
| "@smithy/util-utf8": "^4.1.0", | ||
| "@smithy/fetch-http-handler": "^5.3.0", | ||
| "@smithy/node-http-handler": "^4.3.0", | ||
| "@smithy/types": "^4.6.0", | ||
| "@smithy/util-base64": "^4.2.0", | ||
| "@smithy/util-buffer-from": "^4.2.0", | ||
| "@smithy/util-hex-encoding": "^4.2.0", | ||
| "@smithy/util-utf8": "^4.2.0", | ||
| "tslib": "^2.6.2" | ||
@@ -41,0 +41,0 @@ }, |
| module.exports = require("../index.js"); |
| module.exports = require("../index.js"); |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
87032
-1.7%77
-2.53%1908
-0.68%