Answer the question
In order to leave comments, you need to log in
How does react currently work in nodejs?
Hey
proto.sendFile = function (dirname, filename) {
// Контекст this это res
var filename = filename ? dirname + filename : dirname
var file = new fs.ReadStream(filename)
file.on("error", function (err) {
console.log("Error reading file %s : %s", filename, err)
})
this.on("close", function () {
file.destroy()
})
file.pipe(this)
}
close
for the object response
, but I need it when the user’s speed is low and the user disconnected when uploading half of the file, and if he disconnects when uploading half of the file, it all hangs in memory. ReadStream {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 65536,
buffer: [],
length: 0,
pipes: null,
pipesCount: 0,
flowing: null,
ended: false,
endEmitted: false,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events: { end: [Function], error: [Function] },
_eventsCount: 2,
_maxListeners: undefined,
path: './config.js',
fd: null,
flags: 'r',
mode: 438,
start: undefined,
end: undefined,
autoClose: true,
pos: undefined }
Answer the question
In order to leave comments, you need to log in
Nothing will hang in memory, file.destroy() on this.on("close"... does not need to be called either in case of success or in case of error, after calling pipe everything will happen automatically.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question