2.0.6 • Published 4 years ago

prose_file v2.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

prose_file

Copyright (c) 2020 Seán D. Murray SEE MIT LICENSE FILE

A file Utiliy. Make writing node easier, prettier and less error prone. Writes and reads more like prose

Synopsis

exists(filePath): true if a file exists notExists(filePath): false if a file exists StreamReadLines: Stream a file, line by line. temp: Create a temp file that cleans itself up.

Usage

const file_util = require('prose_file');

/////////////////////// LINE STREAM EXAMPLE ///////////////////
// Stream read a file large or small, line by line.
const streamReadLines = new file_util.StreamReadLines();
class TestWritable extends stream.Writable {
	constructor(options){
		super(options)
	}
	
	_write(chunk, encoding, callback){
		// Do something here with the lines as they arrive.
		const line = chunk.toString();
		console.log(line);
		callback();
	}

}
const testWritable = new TestWritable();
const fileStream =  fs.createReadStream('Some/File/Path/here');
fileStream
	.pipe(streamReadLines)
	.pipe(testWritable);

streamReadLines.on("error",(err)=>{
  // There was an error reading the stream...
});

testWritable.on("finish",()=>{
  // Do something, now that streaming is done.
});
/////////////////////// END ///////////////////

// The .xxx is an optional postfix, if not present will be '.tmp'.
// An optional prefix can be added too, if not present, no prefix is used.
// File is created in the OS default temperary directory.
// The file will be deleted if it exists when the program EXITS!
file_util.temp('.xxx', 'someOptionalPrefix');
2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago