Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rxtoolkit/fs
💾 RxJS utilities for working with files and file streams locally
https://github.com/rxtoolkit/fs
files filesystem fp functional-programming observables package reactive-programming rxjs
Last synced: 11 days ago
JSON representation
💾 RxJS utilities for working with files and file streams locally
- Host: GitHub
- URL: https://github.com/rxtoolkit/fs
- Owner: rxtoolkit
- License: mit
- Created: 2021-03-18T02:10:05.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-16T18:40:02.000Z (11 months ago)
- Last Synced: 2024-12-16T00:22:21.599Z (about 1 month ago)
- Topics: files, filesystem, fp, functional-programming, observables, package, reactive-programming, rxjs
- Language: JavaScript
- Homepage:
- Size: 470 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# @rxtk/fs
> 💾 RxJS operators and utilities for working with files and file streams locally## Installation
This is a private package. It requires setting up access in your npm config.```bash
npm i @rxtk/fs
``````bash
yarn add @rxtk/fs
```## API
### `appendToFile`
Appends a stream of data to a file:
```javascript
import path from 'path';
import {of} from 'rxjs';
import {appendFile} from 'rxfs';const data = [
'"animal","coolness"',
'"dolphin",10',
'"algea",1',
'"mermaid",6',
'"octopus",9',
'"octopus",9',
'"narwhale",8',
];const writeStream$ = of(...data).pipe(
appendFile({filePath: path.resolve(__dirname, './output.csv')})
);
// write the input observable to the file
writeStream$.subscribe(console.log);
```### `fromFile`
Streams data from a file as a stream of Buffers.
```js
import path from 'path';
import {fromFile} from '@rxtk/fs';const csvContentAsBuffer$ = fromFile({
filePath: path.resolve(__dirname, './my-csv.csv'),
});
csvContentBuffer$.subscribe(console.log);
// "name","scariness"
// "Blackbeard",10
// "Morgan",9
// "Sparrow",2
// "Crunch",1
```### `shortenChunks`
Takes a stream of Buffer objects and ensures that they are shortened to the desired size, while preserving order/sequence. Useful, for example, if you want to control the size of a file upload.
```js
import path from 'path';
import {fromFile,shortenChunks} from '@rxtk/fs';const csvContentAsBuffer$ = fromFile({
filePath: path.resolve(__dirname, './my-csv.csv'),
});
const chunkSize = 512;
const shortenedBuffer$ = fileChunk$.pipe(
shortenChunks(chunkSize)
);
shortenedBuffer$.subscribe(console.log);
```### `writeToFile`
Writes data to file (overwriting any previous contents).
```js
import path from 'path';
import {of} from 'rxjs';
import {writeToFile} from '@rxtk/fs';const data = [
'"animal","coolness"',
'"dolphin",10',
'"algea",1',
'"mermaid",6',
'"octopus",9',
'"octopus",9',
'"narwhale",8',
];const writeStream$ = of(...data).pipe(
writeToFile({filePath: path.resolve(__dirname, './output.csv')})
);
// write the input observable to the file
writeStream$.subscribe(console.log);
```