Answer the question
In order to leave comments, you need to log in
Error when working with fs.ReadStream: getting empty data on last on('readable'). Why?
Hey!
Code (training):
'use strict';
let fs = require('fs');
module.exports = (res, filePath) => {
let stream = new fs.ReadStream(filePath);
stream
.on('readable', () => {
console.log('on readable');
let data = stream.read();
res.write(data); // <=== здесь ошибка
})
.on('end', () => { // <-- сюда не заходит
console.log('on end');
res.end('');
})
.on('close', () => { // <-- сюда не заходит
console.log('on close');
})
.on('error', (err) => { // <-- сюда не заходит
console.log('on error :: ' + err.code + '; ' + err.message);
res.statusCode = 400;
res.end('Bad request');
})
;
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question