Open
Description
A JS class that would use a file to CRUD CSV records:
- CSV supports new lines and commas and double-double quotes, escaped inside double quote delimited blocks
- one can create/open a file with a list of column headers and a column for a unique identifier
- if the file exists, the first line of the file will be compared against the column headers and an error thrown if different
- if file does not exist, the header line will be created
- when first opening the file and changing it, cache:
- file update timestamp
- unique index, position of each line
- on change, always check the timestamp of the file has not changed, throw an error if it has
- on read by index, just read the line with position in a buffer of fixed length. if you cannot find the end of the line, just load another buffer and continue
- although here a maximum reasonable buffer like 65536 would be enough
- on insert, just append the line at the end
- on update:
- if the length of the new line is smaller than the existing one, just overwrite it and fill rest with blanks
- if the length is larger, delete the line and insert the new one
- on delete, fill the entirety of the line with blanks
- add a defragmentation method to rewrite the file in place and remove empty space
Metadata
Metadata
Assignees
Labels
No labels