Skip to content

Emit data event data as a Buffer#11

Open
deathcap wants to merge 1 commit intomax-mapper:masterfrom
deathcap:buffer
Open

Emit data event data as a Buffer#11
deathcap wants to merge 1 commit intomax-mapper:masterfrom
deathcap:buffer

Conversation

@deathcap
Copy link
Copy Markdown

For piping workerstreams to other streams (I'm using a websocket-stream) it is convenient for the data event payload to be of type Buffer, instead of Uint8Array. This PR checks whether the event data is a typed array, and if so converts it to a (browserify) buffer using typedarray-to-buffer. browserify-buffers are simply augmented Uint8Arrays, so typedarray-to-buffer is a zero-copy operation.

websocket-stream also performs a Buffer conversion, here: max-mapper/websocket-stream@0089ece#diff-168726dbe96b3ce427e7fedce31bb0bcR58 (as of 1.0.0) - so I think it makes sense for workerstream to do so as well (with pre-1.0 versions of websocket-stream, I ran into the same problem being fixed here in workerstream)

deathcap added a commit to voxel/voxel-clientmc that referenced this pull request Mar 25, 2015
@deathcap
Copy link
Copy Markdown
Author

Not 100% sure this is the right approach, made this also: https://github.com/deathcap/tobuffer-stream can pipe as follows (works with workerstream 1.2.1): self.parentStream.pipe(toBufferStream)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant