Provides random access to keyed lines of arbitrarily sized files.
If you have a file larger than memory that you want to retrieve rows from at random, and your file happens to be structured such that the first word of each line can be regarded as a key for the entire line, well, then this is what you've been looking for.
const randomLineAccess =let rla =rlarlalet rla =rlalet rla =rlalet rla =rlarlarlarla
randomLineAccess(filePath, opts) Careful: the set operator has write permission
omitEmptyExpects a boolean, defaults to true. Removes empty values.
quotesExpects a boolean, defaults to false. Accepts quotes in the key value (IS IGNORED IN SEPARATED VALUES)
sepExpects a string. When provided, returns values seperated by the separator, and inserts arrays joined by seperator.
Returns an instance.
But, if you are curious: what it does concretely is scan the provided file for line breaks, stores the offsets to each key, length of each line in a hash. On get, it uses these together to calculate and pluck the lines on request.
Takes a key and returns the value retrieved to the callback.
set(key, buffer, callback)Careful: the set operator has write permission, and no undo
Takes a key, and either a buffer or a string. If the resulting buffer from the string or buffer is longer than the line in the document then this will raise an error. Dynamic reassignment of sizes is not supported because the author did not need it, nor did the author know an easy way to implement non-destructive insertion and efficient offset updates.
Returns all keys found in the document. Remember, keys are assumed to be the first string in the beginning of each line in the document.
Closes the file.
$ npm install random-line-access