Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Support for writing TypedArray's (e.g. UInt8Array) #547

Closed
jd20 opened this issue Sep 30, 2017 · 3 comments
Closed

Support for writing TypedArray's (e.g. UInt8Array) #547

jd20 opened this issue Sep 30, 2017 · 3 comments

Comments

@jd20
Copy link

jd20 commented Sep 30, 2017

With recent support in RN for TypedArray's, is there a way (or planned support) for writing them directly, instead of base64 strings or normal arrays? For example, I tried something simple like:

const fs = RNFetchBlob.fs
const dirs = RNFetchBlob.fs.dirs
let path = dirs.DocumentDir + '/test.txt'

let arr = new Uint8Array(10)
fs.writeFile(path, arr, 'ascii')
 .then(() => console.log("Wrote data to: " + path))

And this results in an Error: Expected "data" is an Array when encoding is "ascii", however got object. For now, I'm working around the issue by converting to a normal array like this:

let arr2 = Array.prototype.slice.call(arr)
arr2.length === arr.length
arr2.constructor === Array
fs.writeFile(path, arr2, 'ascii')
  .then( ... )

However, I'm thinking there's some performance overhead to this, as it's creating a shallow copy of the entire array (not as bad as Base64 encoding I guess). Would it make sense to add support for RFNB to accept TypedArray's directly?

@lll000111
Copy link
Contributor

lll000111 commented Sep 30, 2017

With recent support in RN for TypedArray's

Do you have a link?

There is nothing new here: https://facebook.github.io/react-native/docs/native-modules-ios.html#argument-types Also didn't find anything on the RN blog.

@jd20
Copy link
Author

jd20 commented Oct 1, 2017

Not sure if I'm misunderstanding what TypedArray support in RN means, but I was going off this WebKit bug report and facebook/react-native#1424. With a fresh RN 0.48.4 project, I'm able to declare and populate UInt8Array's OK. I thought in older RN versions the TypedArray variants weren't present?

@lll000111
Copy link
Contributor

lll000111 commented Oct 1, 2017

The reason that issue is closed is this:

We are trying to keep issues focused on bugs and this is more of a feature request,

So, no, there is no support yet. Please reopen when there is, I'll be the first one to implement the Android side, albeit for the fs functions only (I don't touch the fetch code) since we need it ourselves.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants