Fast JSON data disk read/write.
Efficiently read and write well-formed JSON data to the disk. About x1.5-2 times as fast as JSON.parse/stringify.
import { Literal, parse, stringify } from 'fast-json-data'
const schema = [[Literal, [
'_id',
'_rev',
'name',
'homepage',
['versions', ['*', [
'name',
'gitHead',
['os', [Literal]],
['cpu', [Literal]],
['engines', ['*']],
['dist', [
'shasum',
'tarball',
'unpackedSize',
]],
['dependencies', [
'*',
]],
]]],
['time', ['*']],
]]]
...
// packumentCache is a Map<string, Packument>
await fsp.writeFile(
options.packumentCachePath,
stringify(schema, [...packumentCache]),
'utf-8'
)
...
json = parse(schema, await fsp.readFile(options.packumentCachePath, 'utf-8'))
# parse
(schema, input)
src/fast-json-data.ts#L62 # parseLines
(schema, input)
src/fast-json-data.ts#L66 # stringify
(schema, input)
src/fast-json-data.ts#L3 All contributions are welcome!