Permalink
Cannot retrieve contributors at this time
47 lines (47 sloc)
1.6 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/@azure/storage-blob/dist-esm/storage-internal-avro/src/AvroReadableFromBlob.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) Microsoft Corporation. | |
// Licensed under the MIT license. | |
import { AvroReadable } from "./AvroReadable"; | |
import { AbortError } from "@azure/abort-controller"; | |
const ABORT_ERROR = new AbortError("Reading from the avro blob was aborted."); | |
export class AvroReadableFromBlob extends AvroReadable { | |
constructor(blob) { | |
super(); | |
this._blob = blob; | |
this._position = 0; | |
} | |
get position() { | |
return this._position; | |
} | |
async read(size, options = {}) { | |
size = Math.min(size, this._blob.size - this._position); | |
if (size <= 0) { | |
return new Uint8Array(); | |
} | |
const fileReader = new FileReader(); | |
return new Promise((resolve, reject) => { | |
function cleanUp() { | |
if (options.abortSignal) { | |
options.abortSignal.removeEventListener("abort", abortHandler); | |
} | |
} | |
function abortHandler() { | |
fileReader.abort(); | |
cleanUp(); | |
reject(ABORT_ERROR); | |
} | |
if (options.abortSignal) { | |
options.abortSignal.addEventListener("abort", abortHandler); | |
} | |
fileReader.onloadend = (ev) => { | |
cleanUp(); | |
resolve(new Uint8Array(ev.target.result)); | |
}; | |
fileReader.onerror = () => { | |
cleanUp(); | |
reject(); | |
}; | |
fileReader.readAsArrayBuffer(this._blob.slice(this._position, (this._position += size))); | |
}); | |
} | |
} | |
//# sourceMappingURL=AvroReadableFromBlob.js.map |