Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit data event data as a Buffer #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deathcap
Copy link

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
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