question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

writeStream.write callback

See original GitHub issue

When using a write stream, the Node spec says that you can pass in a callback as last argument like this:

var ws = db.createWriteStream();
var o = {key:'k1', value: 'v1'};
ws.write(o, function() {
  console.log('wrote', o);
});

I don’t need the the write stream interface to be 100% compliant, but I do need to get write acknowledges, which the current implementation does not provide.

I looked at the source code and I couldn’t find an obvious way around this (except for reimplementing the write stream on top of db.put and db.del, but I didn’t want to go that way).

For instance, is there any event that is emitted after a flush? I was looking at the drain event emitted here, but I think that _writeBlock is not always true, so I can’t trust that, can I?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:44 (43 by maintainers)

github_iconTop GitHub Comments

2reactions
rvaggcommented, Jul 21, 2013

Also, I think this thread needs an appropriate gif for write stream optimisation

SQUEEEZE

0reactions
ralphtheninjacommented, Mar 16, 2015

@pgte Closing this because write-stream removal in 1.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Can Callback for stream.write Reliably Verify That ...
The writable.write() method writes some data to the stream, and calls the supplied callback once the data has been fully handled. If an...
Read more >
Stream | Node.js v19.3.0 Documentation
The 'error' event is emitted if an error occurred while writing or piping data. The listener callback is passed a single Error argument...
Read more >
Node.js Stream writable.write() Method - GeeksforGeeks
The callback function is called once the data has been completely handled. Syntax: writable.write( chunk, encoding, callback).
Read more >
fs.WriteStream.end JavaScript and Node.js code examples
function createApiFile(idApplication, nameDataEntity, callback) { // CREATE ROUTE FILE var ... toLowerCase() + '.js'); writeStream.write(apiTemplate); ...
Read more >
WriteStream | typescript - v3.7.7
Inherited from WriteStream.constructor ... _destroy(error: Error | null, callback: function): void. Inherited from Duplex. ... Inherited from Socket.write.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found