Socket
Socket
Sign inDemoInstall

asyncplify-fs

Package Overview
Dependencies
16
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    asyncplify-fs

asyncplify wrappers around some of the node fs lib


Version published
Maintainers
1
Install size
509 kB
Created

Readme

Source

asyncplify-fs

asyncplify wrappers around some of the node fs lib

Installation

npm install asyncplify-fs

Documentation

fromPaged(options)

Asynchronously reads multiple files from disk and returns the items.

options:

  • autoDelete Boolean default = false
  • filenames Array

Example:

fs.writeFileSync('page1.json', [1, 2]);
fs.writeFileSync('page2.json', [3, 4]);

asyncplifyFs
	.fromPaged(['page1.json', 'page2.json'])
	.subscribe({
		emit: function (data) {
			console.log(data);
		},
		end: function (err) {
			if (err) throw err;
		}
	});
    
    // 1
    // 2
    // 3
    // 4
    // end.

When autoDelete = true, the the files are automatically deleted from the disk once loaded.

readFile(options)

Asynchronously reads the entire contents of a file.

options:

  • path String
  • encoding String | Null default = null
  • flag String default = 'r'

Example:

asyncplifyFs
	.readFile('/etc/passwd')
	.subscribe({
		emit: function (data) {
			console.log(data);
		},
		end: function (err) {
			if (err) throw err;
		}
	});

toPaged(options)

Asynchronously write a page of items to files on disk and returns the filename. The filenames are generated based on temp folder.

options:

  • beforeSaving Function
  • size Number default = 0

Example:

asyncplify
	.fromArray([0, 1, 2, 3, 4, 5])
	.pipe(asyncplifyFs.toPaged(2))
	.subscribe(emit: console.bind(console));

    // /user/temp/1231nnuukkasdppasd
	// /user/temp/488fdjj31n324nuukd-sspsd
	// /user/temp/9003403mmfjue003-llhpt
    // end.

The beforeSaving functions allow to transform the items prior to saving, such as sorting, etc. When the size is not provided, the method will produce a single page containing all items.

writeFile(options)

Asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer.

options:

  • path String
  • data String | Buffer
  • encoding String | Null default = 'utf8'
  • mode Number default = 438
  • flag String default = 'w'

Example:

asyncplifyFs
	.writeFile({
		path: 'message.txt',
		data: 'Hello asyncplify'
	})
	.subscribe({
		emit: function (data) {
			console.log(data);
		},
		end: function (err) {
			if (err) throw err;
		}
	});

License

The MIT License (MIT)

Copyright (c) 2015 Dany Laporte

Keywords

FAQs

Last updated on 22 Jul 2015

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