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
{{ message }}
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
The text was updated successfully, but these errors were encountered:
williamstein
changed the title
uncaught exception when using the synchronize decode function
uncaught exception when using the synchronous "decode" function
Nov 17, 2023
I used the following async code as a workaround, for anybody who sees this. This took me a while to work out, but does properly allow for dealing with error cases...
import{createDecoderStream,createEncoderStream}from"lz4";import{createReadStream,createWriteStream}from"fs";import{PassThrough}from"stream";exportasyncfunctionreadFileLz4(path: string): Promise<Buffer>{constdecoder=createDecoderStream();constinput=createReadStream(path);constoutput=newPassThrough();input.pipe(decoder).pipe(output);constchunks: Buffer[]=[];constwaitForFinish=newPromise((resolve,reject)=>{decoder.on("error",reject);output.on("finish",resolve);output.on("error",reject);output.on("data",(chunk)=>{chunks.push(chunk);});});awaitwaitForFinish;returnBuffer.concat(chunks);}exportasyncfunctionwriteFileLz4(path: string,contents: string){// We use a stream instead of blocking in process for compression// because this code is likely to run in the project's daemon,// and blocking here would block interactive functionality such// as terminals.// Create readable stream from the input.constinput=newReadable({read(){this.push(contents);this.push(null);},});// lz4 compression encoderconstencoder=createEncoderStream();constoutput=createWriteStream(path);// start writinginput.pipe(encoder).pipe(output);// wait until doneconstwaitForFinish=newPromise((resolve,reject)=>{encoder.on("error",reject);output.on("finish",resolve);output.on("error",reject);});awaitwaitForFinish;}
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm using nodejs.
Unfortunately, this makes decode unusable in certain robust applications. The underlying code I
think forgets to listen to an error event.
The text was updated successfully, but these errors were encountered: