[PD-dev] Best practices for dealing with binary data in externals

Thomas Mayer thomas at residuum.org
Wed Jul 10 23:05:51 CEST 2013


Hello,

I am pondering about a feature request for PuREST JSON to being able to
download binary data:

https://github.com/residuum/PuRestJson/issues/22

Currently, [rest] and [oauth] output the downloaded data as a symbol on
its left outlet, and binary data is output as a symbol, as long as there
is not any 0 byte in it. But then, the data is not really useful.

So I am thinking of several possibilities, and I want to implement the
feature in the most idiomatic way possible:

1. Add a pseudo HTTP verb BINARYGET with an additional parameter, that
contains the path where the content will be downloaded. After the
request has ended, the file will be written, and the right outlet of the
object will output the status of the request as with the other HTTP verbs.

2. Use standard GET verb and decide via reported MIME type whether to
output the data as symbol or write it to a directory, that has been
specified with a [directory( message.

3. Output a pointer to the downloaded data and let another extension
deal with the data (is there any?). Decision about what to do can be
either by MIME type or a special verb.

4. Add another object for binary requests that implements either method
1 or 3.

5. Something else?

Current reasoning:
I prefer 1 or 2, as it is similar to other objects that write files like
[pix_write] or [sfwrite~]. It can also be extended for sending binary
data via HTTP POST or PUT.

Adding pseudo HTTP verbs may not be an intuitive way for doing this, so
2 should be preferred.

But what if the server responds with the wrong MIME type?

And what if the user wants to explicitely download an HTML or JSON file?
OK, in that case, just use [textfile], but this will a semicolon.

I am a little bit confused about the correct way to implement this, any
input is highly appreciated.

Thanks,
Thomas
-- 
"It seems to me, Golan, that the advance of civilization is nothing
but an exercise in the limiting of privacy."
(Janov Pelorat in: Isaac Asimov - Foundation's Edge)
http://www.residuum.org/



More information about the Pd-dev mailing list