P
P
PAJCH2015-12-15 19:45:56
Node.js
PAJCH, 2015-12-15 19:45:56

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)
}

I don’t have an event closefor 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.
Or is it already provided by nodejs?
there is an autoclose property in the ReadStream object, maybe it matters?
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

1 answer(s)
T
Timur Shemsedinov, 2015-12-16
@PAJCH

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 question

Ask a Question

731 491 924 answers to any question