[英]does not write to the created stream writable node.js
let testWriteableStream_1 = fs.createWriteStream("logs/test_profit_1.csv", { flags: 'a' });
let testWriteableStream_2 = false;
let testFlag = { number: 1 };
let testCount = { number: 0 };
let testCountAll = { number: 0 };
function TestWritable2(testWriteableStream_1, testWriteableStream_2, testFlag, testCount, testCountAll) {
let time = new Date().getTime();
console.log('time:', time);
if (testCount.number === 5) {
testWriteableStream_2 = fs.createWriteStream(`logs/test2_profit${time}.csv`, { flags: 'a' });
console.log('testWriteableStream_2._writableState 5:----------------------------------------------', testWriteableStream_2._writableState);
}
if (testCount.number === 10) {
console.log('testWriteableStream_2._writableState 10:----------------------------------------------', testWriteableStream_2._writableState);
testWriteableStream_2.write(`writeableStream_${testCountAll.number}\r\n`);
}
testCount.number++;
}
TestWritable2(testWriteableStream_1, testWriteableStream_2, testFlag, testCount, testCountAll);
The function is called in websocket 'message' event.该函数在 websocket 'message' 事件中被调用。 Message error: iteableStream_2.write is not a function
消息错误:iteableStream_2.write 不是函数
testWriteableStream_2.write(`writeableStream_${testCountAll.number}\r\n`);
^
TypeError: testWriteableStream_2.write is not a function
In the case of testCount.number === 10
you don't create a stream, and testWriteableStream_2
remains false
, which doesn't have a write
method.在
testCount.number === 10
的情况下,您不创建流,并且testWriteableStream_2
保持为false
,它没有write
方法。 Create a stream for this case too, and you should be OK.也为这种情况创建一个流,你应该没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.