You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using fastfile to parse a large .tar file. At first, everything seems to work, but some way in, the following error is thrown:
TypeError: Cannot read property 'buff' of undefined
at FastFile.readToBuffer (C:\dev\rhubarb-2-poc\node_modules\fastfile\build\main.cjs:316:58)
at async readTarFile (C:\dev\rhubarb-2-poc\src\utils\read-tar-file.ts:23:7)
Here's my code. Given that the error only occurs after quite some iterations, I don't have a better way of reproducing the problem.
import{readExisting}from'fastfile';import{utf8ArrayToString}from'./utf8-array-to-string';interfaceTarFileEntry{filePath: string;fileSize: number;getFileBytes(): Promise<Uint8Array>;}exportasyncfunction*readTarFile(tarFilePath: string,): AsyncIterableIterator<TarFileEntry>{constfile=awaitreadExisting(tarFilePath);try{constblockSize=512;constheaderBytes=newUint8Array(blockSize);constfilePathBytes=newUint8Array(headerBytes.buffer,0,100);constfileSizeBytes=newUint8Array(headerBytes.buffer,124,12);letzeroBlockCount=0;while(true){awaitfile.readToBuffer(headerBytes,0,blockSize);// THIS LINE THROWS AFTER SOME ITERATIONSif(headerBytes[0]===0){zeroBlockCount++;// Two consecutive zero blocks indicate end of fileif(zeroBlockCount===2)return;}else{zeroBlockCount=0;}constfilePath=utf8ArrayToString(filePathBytes);constfileSize=parseInt(utf8ArrayToString(fileSizeBytes),8);if(fileSize===0)continue;// directoryconstbufferSize=Math.ceil(fileSize/blockSize)*blockSize;constbufferPosition=file.pos;console.log(filePath);yield{
filePath,
fileSize,asyncgetFileBytes(){if(file.pos!==bufferPosition){thrownewError('Cannot read file once iteration has continued.');}constbufferBytes=newUint8Array(bufferSize);awaitfile.readToBuffer(bufferBytes,0,bufferSize);returnnewUint8Array(bufferBytes.buffer,0,fileSize);},};file.pos=bufferPosition+bufferSize;}}finally{awaitfile.close();}}
The text was updated successfully, but these errors were encountered:
I'm using
fastfile
to parse a large .tar file. At first, everything seems to work, but some way in, the following error is thrown:Here's my code. Given that the error only occurs after quite some iterations, I don't have a better way of reproducing the problem.
The text was updated successfully, but these errors were encountered: