🗑️ Remove old code

This commit is contained in:
C-3PO 2019-07-21 16:22:50 +02:00
parent de5eca71f3
commit 8ae29e6006
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -1,7 +1,5 @@
import * as stream from 'stream'; import * as stream from 'stream';
const BUFFER_SIZE = 16 * 1024;
export default function arrayBufferToStream(arrayBuffer: ArrayBuffer, offset: number = 0, length?: number): stream.Readable { export default function arrayBufferToStream(arrayBuffer: ArrayBuffer, offset: number = 0, length?: number): stream.Readable {
if (offset < 0 || offset >= arrayBuffer.byteLength - 1) { if (offset < 0 || offset >= arrayBuffer.byteLength - 1) {
throw new RangeError('Could not convert ArrayBuffer to ReadableStream; out of bounds.'); throw new RangeError('Could not convert ArrayBuffer to ReadableStream; out of bounds.');
@ -15,7 +13,7 @@ export default function arrayBufferToStream(arrayBuffer: ArrayBuffer, offset: nu
const byteArray = new Uint8Array(arrayBuffer); const byteArray = new Uint8Array(arrayBuffer);
const outStream = new stream.Readable({ const outStream = new stream.Readable({
read(size) { read(size) {
const chunkSize = Math.min(size || BUFFER_SIZE, endPosition - position); //TODO: we can probably remove BUFFER_SIZE const chunkSize = Math.min(size, endPosition - position);
let needMoreData: boolean; let needMoreData: boolean;
do { do {
//If end is reached //If end is reached
@ -29,8 +27,6 @@ export default function arrayBufferToStream(arrayBuffer: ArrayBuffer, offset: nu
for (let i = 0; i < chunkSize; i += 1) { for (let i = 0; i < chunkSize; i += 1) {
chunk.writeUInt8(byteArray[position + i], i); chunk.writeUInt8(byteArray[position + i], i);
} }
//chunk.fill(arrayBuffer, position);
//const chunk = Buffer.from(arrayBuffer, position, chunkSize);
position += chunk.length; position += chunk.length;
needMoreData = outStream.push(chunk); needMoreData = outStream.push(chunk);
} while (needMoreData); } while (needMoreData);