# react-native-file-stream

> operate file stream in react native

Latest version **1.0.4** (published 2023-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-file-stream
pnpm add react-native-file-stream
yarn add react-native-file-stream
bun add react-native-file-stream
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2023-03-18 |
| First published | 2023-03-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 27 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wanxianliang |
| Maintainers | xianliang |
| Keywords | react-native, react-native-file, react-native-file-stream, react-native-file-write-stream, react-native-file-read-stream |

## Links

- npm: https://www.npmjs.com/package/react-native-file-stream
- Homepage: https://github.com/wanxianliang/react-native-file-stream
- npm.io page: https://npm.io/package/react-native-file-stream

## Dependencies (1)

- [base64-arraybuffer](https://npm.io/package/base64-arraybuffer.md) ^1.0.2

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2023-03-18
- 1.0.4-beta2 — 2023-03-17
- 1.0.4-beta — 2023-03-17
- 1.0.3 — 2023-03-13
- 1.0.3-alpha.1 — 2023-03-13
- 1.0.3-alpha.0 — 2023-03-13
- 1.0.3-alpha — 2023-03-13
- 1.0.2 — 2023-03-12
- 1.0.1 — 2023-03-12
- 1.0.0 — 2023-03-12

## README

# **react-native-file-stream**

### **Description**

The `react-native-file-stream` library provides a convenient way to manipulate file streams on Android.

## **Getting started**

To install the library, run the following command:

```
$ npm install react-native-file-stream --save
```

### **Mostly automatic installation (for React Native version < 0.60)**

To link the library, run the following command:

```
$ react-native link react-native-file-stream
```

### **Important**

#### The way we read file

![read](http://cdnqiniu.xiaozhitodo.com/tos/write.png)

#### The way we write file

![write](http://cdnqiniu.xiaozhitodo.com/tos/read.png)

### **Reading files**

**To read a file, follow these steps:**

1. Convert `base64Data` to `ArrayBuffer`. `ArrayBuffer` contains the original data.
2. Convert `ArrayBuffer` data to text or any other type of data you want.

### **Writing files**

**To write a file, follow these steps:**

1. Convert your origin data to `ArrayBuffer`.
2. Convert `ArrayBuffer` data to `base64Data`.
3. Invoke the `writeFileStream` method to write data.

## **Usage**

### **Read file as stream**

```javascript
import ReactNativeFileStream from "react-native-file-stream";

let bufferSize = 1024 * 127;
ReactNativeFileStream.readFileStream({
    uri: "content://xxxx.png",
    fileName: "xxxx.png",
    fileSize: 120023
}, bufferSize, (event) => {
    const data = event?.data;
    const hasMore = event?.hasMore;
    if (hasMore == false) {
        // Finish reading.
    }
    if (data) {
        // This is `base64Data`.
    }
})
```

### **Write file as stream**

```javascript
import ReactNativeFileStream from "react-native-file-stream";

// 1. Init file write stream.
let path = "file://xxxx";
ReactNativeFileStream.initWriteFileStream(path);

// 2. Append data.
let base64Data = "cGxlYXNlIGdpdmUgbWUgYSBzdGFydA==";
ReactNativeFileStream.writeFileStream(path, base64Data);

// 3. Stop writing file.
ReactNativeFileStream.stopWriteFileStream(path);
```

### **Data Conversion Methods**

```javascript
import ReactNativeFileStream, { DataConvertUtils } from "react-native-file-stream";

const base64DataStr = "cGxlYXNlIGdpdmUgbWUgYSBzdGFydA==";
const arrayBufferData = DataConvertUtils.base64ToArryBuffer(base64DataStr);
const base64Data2 = DataConvertUtils.arryBufferToBase64(arrayBufferData);

const unit8ArrayData = DataConvertUtils.base64ToUnit8Array(base64DataStr);
const base64Data3 = DataConvertUtils.unit8ArrayToBase64(unit8ArrayData);

```

If you find this project helpful, please give it a star on [my Github Repo](https://github.com/wanxianliang/react-native-file-stream). Thank you!

---
_Source: https://npm.io/package/react-native-file-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
