Download piped streams on Node.js server

donloaded ok:

const emit = r.emit;
r.emit = (...a) => a[0] != 'drain' && q.log.debug('response event:', a[0]) || emit.apply(r, a);

response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: prefinish
response event: finish
response event: unpipe
response~~ stream ended

download boke:

response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: drain
response event: close
response event: unpipe
response~~ stream ended

https://nodejs.org/api/http.html#http_response_addtrailers_headers

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer

file read stream

> s = require('fs').createReadStream('./package.json').pause();1
1
> emit=s.emit;s.emit=(...a)=>console.log(a[0])||emit.apply(s,a);1
1
> destroy=s.destroy;s.destroy=(...a)=>console.log(new Error('DESTROY').stack)||destroy.apply(s);1
1
> close=s.close;s.close=(...a)=>console.log(new Error('CLOSE').stack)||close.apply(s);1
1
> s.pipe(w);1
1
> resume
data
end
Error: DESTROY
    at ReadStream.s.destroy.a [as destroy] (repl:1:49)
    at ReadStream.<anonymous> (fs.js:1973:12)
    at emitNone (events.js:111:20)
    at ReadStream.emit (events.js:208:7)
    at ReadStream.s.emit.a [as emit] (repl:1:52)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)
Error: CLOSE
    at ReadStream.s.close.a [as close] (repl:1:43)
    at ReadStream._destroy (fs.js:2054:8)
    at ReadStream.destroy (internal/streams/destroy.js:32:8)
    at ReadStream.s.destroy.a [as destroy] (repl:1:86)
    at ReadStream.<anonymous> (fs.js:1973:12)
    at emitNone (events.js:111:20)
    at ReadStream.emit (events.js:208:7)
    at ReadStream.s.emit.a [as emit] (repl:1:52)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
close
Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com