diff --git a/src/ssn/streams/getFileFromDisks.ts b/src/ssn/streams/getFileFromDisks.ts index 1b578f4..81cf273 100644 --- a/src/ssn/streams/getFileFromDisks.ts +++ b/src/ssn/streams/getFileFromDisks.ts @@ -12,7 +12,7 @@ interface IGetFileFromDisksOptions { } function getStream(disks: string[], index: number, offset: number, length: number = Infinity) { - return fs.createReadStream(disks[index], { start: offset, end: offset + length - 1 }); + return fs.createReadStream(disks[index], { start: offset }); //, end: offset + length - 1 }); } /** Takes a list of ReadableStreams (the disks), as well as the offset and length, and returns a stream for just one file. */ @@ -23,37 +23,15 @@ export default async function getFileFromDisks(disks: string[], { diskStart, off let totalRead = 0; //Create new stream that concatenates disks until storedSize is reached, then ends the stream. - const outputStream = new stream.PassThrough({ - /*read(num) { - if (num === undefined) { - throw new Error('Expected to receive number of bytes when reading from stream.'); - } - - totalRead += num; - //end of file reached - if (localFileHeaderLength !== 0 && totalRead >= localFileHeaderLength + storedSize) { - return null; - } - - const chunk = curDisk.read(num); - //transparently switch to next disk as soon as we finished reading current disk - if (chunk === null) { - curDiskIndex += 1; - curDisk = getStream(disks, curDiskIndex, 0, (localFileHeaderLength === 0) ? Infinity : localFileHeaderLength + storedSize - totalRead); - //TODO: await new Promise((resolve) => { curDisk.on('readable', () => { resolve(); }); }); - return curDisk.read(num); - } else { - return chunk; - } - },*/ - }); + const outputStream = new stream.PassThrough(); const onData = (chunk: Buffer) => { outputStream.write(chunk); totalRead += chunk.length; - //TODO: need to end if we have read beyond the file + //need to end if we have read beyond the file + //TODO: need to also shorten chunk if file ended inside it, before writing it to PassThrough. if (localFileHeaderLength !== 0 && totalRead >= localFileHeaderLength + storedSize) { - //TODO + outputStream.end(); } }; const onError = (error: any) => {