M
M
Maximys7812018-03-14 17:16:09
Node.js
Maximys781, 2018-03-14 17:16:09

Why is END READ output, but the part before it is not output?

The console output is END READ, and the previous part is cut off. I must say right away that in previous programs this scheme worked as it should.
PS Yes, I may not see the obvious error. To some extent, I may not understand something. But I am writing a question in order to understand and understand.
Thanks in advance.

var fs=require ('fs');
var streamwrite=new fs.WriteStream(__dirname+"/read.txt",'utf-8');
var streamread=new fs.ReadStream(__dirname+"/read.txt",'utf-8');
streamread.on('data',function(chunk){
    console.log("Date accepted:\n"+chunk);
    streamwrite.write("Privet");
    console.log("Dannie zapisani");
  });
streamread.on('end',function(){
  console.log("THE END READ");
});
streamread.on('error',function(err){
  if(err=='ENOENT'){
    console.log("File not found");
  }
  else{
    console.error(err);
  }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RidgeA, 2018-03-14
@Maximys781

wrong streams are created:
https://nodejs.org/dist/latest-v9.x/docs/api/fs.ht...
https://nodejs.org/dist/latest-v9.x/docs/api/ fs.ht...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question