tie-file
A port(ish) of Tie::File, this creates an array-like object with the contents of a file on disk, where all modifications are written to the file automatically.
Usage
var tieFile = // File will be created on first modification if it doesn't existvar file = file; // line 13 of the file is now 'blah'console; // display line 42 of the file nRecs = filelength; // how many records are in the file?file // chop two records off the end // Replace javascript with JavaScript everywhere in the filefile // These are just like regular push, pop, unshift, shift, and splice// Except that they modify the file in the way you would expect file;var r1 = file;file;var r2 = file;var oldRecs = file; // file is an EventEmitterfile
Status
Very incomplete, untested, something of a PoC at this point.
In-place modification of lines
Line objects act like strings but add a few extra methods that allow them to be modified in-place:
swap(string)
Replace the line with string
.
inPlace(pattern, replacement)
Just like String.prototype.replace, but will swap
the line with the return value.
{prepend, append}(string...)
Places one or more strings at the start/end of the line.
Caveats
Array access doesn't work (yet?), for now you must use the get
/set
methods. I'm not sure how best to do this without resorting to ES6 proxies.
License
BSD