@smithy/chunked-blob-reader
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -26,25 +26,10 @@ var __defProp = Object.defineProperty; | ||
module.exports = __toCommonJS(src_exports); | ||
function blobReader(blob, onChunk, chunkSize = 1024 * 1024) { | ||
return new Promise((resolve, reject) => { | ||
const fileReader = new FileReader(); | ||
fileReader.addEventListener("error", reject); | ||
fileReader.addEventListener("abort", reject); | ||
const size = blob.size; | ||
let totalBytesRead = 0; | ||
function read() { | ||
if (totalBytesRead >= size) { | ||
resolve(); | ||
return; | ||
} | ||
fileReader.readAsArrayBuffer(blob.slice(totalBytesRead, Math.min(size, totalBytesRead + chunkSize))); | ||
} | ||
__name(read, "read"); | ||
fileReader.addEventListener("load", (event) => { | ||
const result = event.target.result; | ||
onChunk(new Uint8Array(result)); | ||
totalBytesRead += result.byteLength; | ||
read(); | ||
}); | ||
read(); | ||
}); | ||
async function blobReader(blob, onChunk, chunkSize = 1024 * 1024) { | ||
const size = blob.size; | ||
let totalBytesRead = 0; | ||
while (totalBytesRead < size) { | ||
const slice = blob.slice(totalBytesRead, Math.min(size, totalBytesRead + chunkSize)); | ||
onChunk(new Uint8Array(await slice.arrayBuffer())); | ||
totalBytesRead += slice.size; | ||
} | ||
} | ||
@@ -51,0 +36,0 @@ __name(blobReader, "blobReader"); |
@@ -1,23 +0,9 @@ | ||
export function blobReader(blob, onChunk, chunkSize = 1024 * 1024) { | ||
return new Promise((resolve, reject) => { | ||
const fileReader = new FileReader(); | ||
fileReader.addEventListener("error", reject); | ||
fileReader.addEventListener("abort", reject); | ||
const size = blob.size; | ||
let totalBytesRead = 0; | ||
function read() { | ||
if (totalBytesRead >= size) { | ||
resolve(); | ||
return; | ||
} | ||
fileReader.readAsArrayBuffer(blob.slice(totalBytesRead, Math.min(size, totalBytesRead + chunkSize))); | ||
} | ||
fileReader.addEventListener("load", (event) => { | ||
const result = event.target.result; | ||
onChunk(new Uint8Array(result)); | ||
totalBytesRead += result.byteLength; | ||
read(); | ||
}); | ||
read(); | ||
}); | ||
export async function blobReader(blob, onChunk, chunkSize = 1024 * 1024) { | ||
const size = blob.size; | ||
let totalBytesRead = 0; | ||
while (totalBytesRead < size) { | ||
const slice = blob.slice(totalBytesRead, Math.min(size, totalBytesRead + chunkSize)); | ||
onChunk(new Uint8Array(await slice.arrayBuffer())); | ||
totalBytesRead += slice.size; | ||
} | ||
} |
/** | ||
* @internal | ||
* Reads the blob data into the onChunk consumer. | ||
*/ | ||
export declare function blobReader(blob: Blob, onChunk: (chunk: Uint8Array) => void, chunkSize?: number): Promise<void>; |
/** | ||
* @internal | ||
* Reads the blob data into the onChunk consumer. | ||
*/ | ||
export declare function blobReader(blob: Blob, onChunk: (chunk: Uint8Array) => void, chunkSize?: number): Promise<void>; |
{ | ||
"name": "@smithy/chunked-blob-reader", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"scripts": { | ||
@@ -9,3 +9,3 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'", | ||
"build:types": "yarn g:tsc -p tsconfig.types.json", | ||
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4", | ||
"build:types:downlevel": "rimraf dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4", | ||
"stage-release": "rimraf ./.release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz", | ||
@@ -12,0 +12,0 @@ "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 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
15827
57