Streaming binary audio data from server (node.js) to client (browser) and allow client to save the audio file when done receiving

1,672 views
Skip to first unread message

Tom

unread,
Mar 27, 2011, 8:30:34 AM3/27/11
to nod...@googlegroups.com
Dear all,

I am trying to proxy audio data from browser A to browser B through the node.js server (using multipart uploading).

When the server receives chunks of binary data, it sends these to browser B.

My question is, how would browser B convert this binary audio data to an actual audio file and allow the user to save this file on his or her hard drive?

Has anything related ever been attempted within the node community?

Any feedback is highly appreciated.

Best regards,
Tom 

mscdex

unread,
Mar 27, 2011, 9:52:51 AM3/27/11
to nodejs
On Mar 27, 8:30 am, Tom <tommed...@gmail.com> wrote:
> My question is, how would browser B convert this binary audio data to an
> actual audio file and allow the user to save this file on his or her hard
> drive?

Probably your best bet would be to transfer the binary data encoded
with base64 to the client, then use something like downloadify
(https://github.com/dcneiner/Downloadify) to save the contents locally.

Tane Piper

unread,
Mar 27, 2011, 12:55:21 PM3/27/11
to nod...@googlegroups.com
Actually just saw this: https://github.com/antimatter15/player

Might be something along the lines of what you need if you stream the
data to local storage in the client

> --
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en.
>

Tom

unread,
Mar 27, 2011, 1:45:00 PM3/27/11
to nodejs
@mscdex,

Downloadify looks great. Unfortunately I need to save multiple files
with preset filenames with the click of a single button though, I
wonder if that is possible at all.

Thanks again.

- Tom

mscdex

unread,
Mar 27, 2011, 3:10:42 PM3/27/11
to nodejs
On Mar 27, 1:45 pm, Tom <tommed...@gmail.com> wrote:
> Downloadify looks great. Unfortunately I need to save multiple files
> with preset filenames with the click of a single button though, I
> wonder if that is possible at all.

Do they really have to be separate? What about tarring/zipping/etc the
files before sending to the client?

Tom

unread,
Mar 27, 2011, 3:24:33 PM3/27/11
to nodejs
@mscdex,

That could work.

In that case, I need to be able to zip the files in a cross-browser
way though.. that sounds like another difficulty.

Thanks again.

Tim Caswell

unread,
Mar 27, 2011, 4:43:03 PM3/27/11
to nod...@googlegroups.com
Creating tar files in JavaScript isn't too hard: https://github.com/creationix/node-tar, especially in node where you have the Buffer data type.  I don't know the zip format, but producing files is easier that consuming them because you only have to support the one variant that you produce.

Tom

unread,
Mar 27, 2011, 4:46:12 PM3/27/11
to nodejs
@Tim Caswell,

Interesting, although I need zip as it is more commonly accepted (and
understood) for the not so technical consumer.

You imply that it is a trivial task (right?), but I cannot seem to
find a cross browser library that does this. It does seem more
difficult than one would think?

Regards,
Tom

mscdex

unread,
Mar 27, 2011, 7:33:49 PM3/27/11
to nodejs
On Mar 27, 3:24 pm, Tom <tommed...@gmail.com> wrote:
> @mscdex,
>
> That could work.
>
> In that case, I need to be able to zip the files in a cross-browser
> way though.. that sounds like another difficulty.

No, I meant archive them on the server end, send the archive binary
data as base64, then use downloadify or similar to download the
archive locally.

To zip files, at the very least you could just stream the data into a
child process that executes a zipping program capable of reading from
stdin and writing the result to stdout.

julien de Nas de Tourris

unread,
Mar 27, 2011, 4:22:00 PM3/27/11
to nod...@googlegroups.com

Why don't u save the binary data to a temp file and resend the all file to the browser B?

Le 27 mars 2011 14:30, "Tom" <tomm...@gmail.com> a écrit :

Johan Steenkamp

unread,
Mar 27, 2011, 6:36:49 PM3/27/11
to nod...@googlegroups.com
Ahh sorry -you want to unzip on the client!

On Mon, Mar 28, 2011 at 11:35 AM, Johan Steenkamp <jo...@orbital.co.nz> wrote:
> http://jszip.stuartk.co.uk/

Johan Steenkamp

unread,
Mar 27, 2011, 6:39:26 PM3/27/11
to nod...@googlegroups.com

Tom

unread,
Mar 28, 2011, 7:07:00 AM3/28/11
to nodejs
@mscdex, @julien,

That beats the point of streaming :)

There are several reasons for zipping on the client side:
1. the server never has to store any data as it simply proxies the
data immediately to browser B
2. the server won't have the overhead of zipping

Where number 1 is of course the most important. The key of my service
is really going to be that node.js merely proxies the data from one
browser to another, faking a p2p environment (where the only cost is
bandwidth and keeping connections alive).

I believe I will have to zip the files with Flash. Since I have to use
Flash anyway for Downloadify, this is not a problem.

Thanks again.

- Tom
Reply all
Reply to author
Forward
0 new messages