Perhaps you could create a branch in your current fork and push a commit there, then create a pull request to safepublishing/rfcs? I never tried that, but maybe it could work…
From the Rust perspective, the most intuitive type might be the std::io::Read
trait. It’s implemented by File
, Stdin
and [u8]
. It has a streaming variant too, BufRead
. So perhaps two add
functions, one accepting Read
, the other BufRead
?
Then, in JavaScript one function could accept string | Uint8Array | ReadableStream
(Node.js’s Buffer
is also an Uint8Array
by the way). I think it’s quite usual that in JavaScript a variety of types is accepted. Then the right Rust/FFI call could be picked by this function depending on whether a chunk or stream is given.
Thus, I think we should start with generalizing the Rust side and then again generalizing the JS/Node.js API so it becomes idiomatic JavaScript.
@joshuef @bochaco evening, I’m doing some more investigation now, specifically with regards to the files_container_add_from_raw
call.
Other files_container_*
methods seem to infer the Content-Type
HTTP header (in the SAFE network FilesMaps this is stored in the value type
.) A .html file will have the type text/html
and it’s essentially a 1-to-1 mapping of MIME types for traditional file types.
If you use the files_container_add_from_raw
function, it stores the type as type: "Raw"
, even if the call you make contains a valid file type for it to hint from:
v.files_container_add_from_raw(new Uint8Array([104, 101, 108, 108, 111]), "hnyynyi95mmtqr9pcwnoft9xwo61w3iu7qmhd415yngihakc1ajrgkiq4ebnc/test.html", true, false, false);
/test.html:
created: "2020-02-13T22:49:40Z"
link: "safe://hbyyyynow943e9j4iwuspmobswb7dmstbzt1d51cssqfsmiun7zjxzrhc8"
modified: "2020-02-13T22:49:40Z"
size: ""
type: "Raw"
Do you think it’s worth me adding a change to this method in this RFC to allow the setting of the type
?
A signature along the lines of:
v.files_container_add_from_raw(buffer, url, force, update_nrs, type, dry_run);
// Example call:
v.files_container_add_from_raw(
new Uint8Array([104, 101, 108, 108, 111]),
"hnyynyi95mmtqr9pcwnoft9xwo61w3iu7qmhd415yngihakc1ajrgkiq4ebnc/test.html",
true,
false,
"text/html; charset=utf-8",
false
);
It’s also not storing the file size of Raw files in the FilesMap (though it is presenting a valid Content-Length
header on download), this is presumably some kind of bug?
Cheers,
Shane
Yep, I think an arg for setting the type is what’s needed there
And size
does indeed sound buggy.