prose_file

2.0.6 • Public • Published

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

Dependencies (3)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i prose_file

    Weekly Downloads

    0

    Version

    2.0.6

    License

    MIT

    Unpacked Size

    14.2 kB

    Total Files

    8

    Last publish

    Collaborators

    • seandmurray