neon-bindings / rfcs

RFCs for changes to Neon
Apache License 2.0
14 stars 9 forks source link

Update docs to access binary data #41

Closed That3Percent closed 3 years ago

That3Percent commented 3 years ago

I spent a while this morning trying to figure out how to get at a JsArrayBuffer as a [u8].

There is this RFC: 0005-array-buffer-views but that doesn't seem to be implemented (at least not as the RFC describes it)

There is also this legacy example: sharing-binary-data but the code there is commented out and wouldn't compile otherwise.

Here's what I arrived at:

if let Ok(buffer) = handle.downcast::<JsArrayBuffer>() {
    let lock = cx.lock();
    let binary = buffer.borrow(&lock);
    let slice: &[u8] = binary.as_slice();
    return Ok(slice.to_owned());
}

Updating this page: Arrays which currently has a broken link to where the legacy example used to be with some explanation of all the nice things you can do with as_slice would be great.

kjvalencik commented 3 years ago

@That3Percent You're right! It does look like the implementation doesn't match the RFC. It is all implemented at least.

I don't see any broken links on the Arrays doc. Which link is broken for you?

I am going to close this issue because the RFCs repo isn't really the best place for it. Also, docs are currently being rewritten for N-API.

Thanks again for your report!

@dherman do you think the merged RFC should be updated or should we leave it since we plan on changing the borrow API slightly for 1.0?

That3Percent commented 3 years ago

It looks like the broken link was fixed this morning (or I was pulling the page from cache before). It had linked to the same url without the "legacy" part and was not found in the new examples repo. (Which gave me a minor panic attack today because I needed to see that code and it was there last time I checked a couple of days ago!)

Sorry I didn't notice I was in the RFC repo. Do you want me to open this issue somewhere else?

kjvalencik commented 3 years ago

@That3Percent the links were fixed a couple days ago, a couple hours after I broke them. 😆 You must have hit the site at exactly the wrong time window! Sorry about that.

In general, I would recommend filing docs issues against the main repo, but given that there's both a docs effort and a borrow RFC being worked on, it's probably unnecessary.

Thanks!

https://github.com/neon-bindings/website/pull/200