node-serialization
A serialization library for node. Serialize/Deserialize a huge object to/from a file.
Using v8 Serialization API as default. You can provide custom serialization functions, like JSON(stringify/parse), json-stream-stringify, etc.
Usage
const readFile writeFile = ;
Default serialize/deserialize method
Write a object to a file and read the file restore a object.
var path = "cache.data";var data = foo: "bar"; ; ;
Custom serialize/deserialize method
Use a custom serialization method.
const serialization = ; const serialize = { return JSON;};const deserialize = { return JSON;}; const readFile: readJsonFile writeFile: writeJsonFile = ; var path = "cache.json";var data = foo: "bar"; ; ;
Convert Format
Deserialize a file then serialize into another file with different serialization.
const convert serializeJson deserialize: deserializeV8 = ; ;
Methods
Async
- readFile
- writeFile
- readJson
- writeJson
- convert
Sync
- readFileSync
- writeFileSync
- readJsonSync
- writeJsonSync
- convertSync
- serialize
- deserialize
- serializeJson
- deserializeJson
If file
parameter is a file path (type is string, not a buffer or a file descriptor), the writeXxx
functions will write content to a temporary file while writing, and rename to the path of file
parameter when success. So even if an exception(such as OOM) occurs, the file will not be a file with content loss.
License
Copyright (c) 2020 dailyrandomphoto. Licensed under the MIT license.