0.5.3 • Published 10 years ago

asyncplify-fs v0.5.3

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

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

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago