Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.
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

Description

@jd20

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions