Socket
Socket
Sign inDemoInstall

@rxtk/fs

Package Overview
Dependencies
3
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @rxtk/fs

💾 RxJS operators and utilities for working with files and file streams locally


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@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.

npm i @rxtk/fs
yarn add @rxtk/fs

API

appendToFile

Appends a stream of data to a file:

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.

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.

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).

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);

Keywords

FAQs

Last updated on 01 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc