-
Notifications
You must be signed in to change notification settings - Fork 10
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
Binary data transfer #33
Comments
Depends on #34 |
Binary streaming in JSTP will be built on top of Node.js Stream API. We need to subclass |
It's better to arrange it in stream initialization packets. The default value should be based on the |
Stream initialization packet: { stream: [42, chunkSize?], metadata: [totalSize?, streamType?, fileName?] } Stream initialization acknowledgement packet: { callback: [42], ok: ['streamId'] } or { callback: [42], error: [ /* error array */ ] } Chunk metadata packet (immediately followed by pure binary data): { data: [234, 'streamId'] } Last chunk metadata packet: { end: [234, 'streamId', chunkSize] } Additional packets for stream state change notifications will be specified later. |
Some notes on remote methods accepting streams as parameters. On low level, each method accepting a stream will actually accept a string — stream identifier (
The remote method will be able to obtain a stream by ...
const stream = connection.streams[streamId];
if (!stream) return callback(new Error('unknown stream'));
stream.on('data', () => { ... });
stream.on('end', () => { ... });
... After #19 and metarhia/impress#608 it will become much nicer to use. The signature of a remote method will specify that a parameter is a stream, and a client will know about that too after retrieving introspection. Thus to call such a method one would just call a method of a proxy object passing any arbitrary readable stream: gallery.uploadPhoto(fs.createReadStream('./photo.jpg')); The proxy object will perform the above steps behind the curtain and pipe the passed stream into an internal JSTP binary stream. Accordingly, a method won't need to obtain the stream explicitly, it will already be passed one instead of |
The text was updated successfully, but these errors were encountered: