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.

Refactoring Client to extend Stream.

See original GitHub issue

I think client should be build on top of a stream.

so you can do client.pipe(fs.createWriteStream('protocol.log'))

client.pipe(new Transform({ writableObjectMode: true, transform(chunk, enc, cb) {
  this.push(JSON.stringify(chunk,null,2);
  cb();
}})).pipe(fs.createWriteStream('protocol.log'));

stream -> [ serializer ] -> [ compressor ] -> framer -> [ cipher ] -> socket socket -> [ decipher ] -> splitter -> [ decompressor ] -> deseralizer -> stream

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rom1504commented, Jul 17, 2017

Ah now I see @roblabla point. Yes you still won’t be able to do

client.pipe(fs.createWriteStream('protocol.log'))

directly.

But you will be able to do

client.pipe(new Transform({writableObjectMode: true,transform(chunk,enc,cb){this.push(JSON.stringify(chunk,null,2);cb();}})).pipe(fs.createWriteStream('protocol.log'))
0reactions
rom1504commented, Jul 17, 2017

well the serializer readable part is object mode https://github.com/ProtoDef-io/node-protodef/blob/master/src/serializer.js#L5 I don’t think that’s a problem.

The difference between the deserializer and your “stream” is only that that “stream” would handle all the states, hence the user of the stream wouldn’t need to care about states.

That just means piping and unpiping the serializer and deserializer to that stream on change of state.

I guess we could then just listen on data of that stream to emit packet event, and write on that stream instead of writing directly on the serializer (for nmp client and server implementation). And expose the stream for people that want to use it directly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dmcg/refactoring-to-streams - GitHub
The general workflow while refactoring towards Streams and lambda expressions is like that: Start by replacing the Iterable in the extended for loop...
Read more >
Optimize Java 8 Streams Refactoring Tool Demonstration
Streaming APIs are pervasive in mainstream Object-Oriented languages and platforms. For example, the Java 8 Stream API allows for ...
Read more >
Safe Automated Refactoring for Intelligent Parallelization of ...
We present a novel refactoring approach for maximizing the efficiency of their Java 8 stream code by automatically determining when it is safe...
Read more >
Kayak: Safe Semantic Refactoring to Java Streams
ABSTRACT. Refactorings are structured changes to existing software that leave its externally observable behaviour unchanged. Their intent is to im-.
Read more >
A Tool for Optimizing Java 8 Stream Software via Automated ...
for optimizing their stream code to its full potential. Index Terms—refactoring, automatic parallelization, typestate analysis, ordering, Java 8, streams, ...
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