🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

node-persist

Package Overview
Dependencies
Maintainers
3
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-persist - npm Package Compare versions

Comparing version

to
4.0.4

5

package.json
{
"name": "node-persist",
"version": "4.0.3",
"version": "4.0.4",
"description": "Super-easy (and fast) persistent data structures in Node.js, modeled after HTML5 localStorage",

@@ -41,2 +41,5 @@ "main": "./src/node-persist.js",

"readmeFilename": "README.md",
"dependencies": {
"p-limit": "^3.1.0"
},
"devDependencies": {

@@ -43,0 +46,0 @@ "chai": "^4.1.2",

41

README.md

@@ -1,3 +0,2 @@

# node-persist
## (localStorage on the server)
# node-persist *- localStorage on the server*

@@ -14,2 +13,12 @@ ### Super-easy asynchronous persistent data structures in Node.js, modeled after HTML5 localStorage

## Table of Contents
[Install](#install)
[Example](#basic-example)
[Change Logs](#change-logs)
[API](#api-documentation)
## Install

@@ -44,5 +53,13 @@

```
## Change Logs
## 3.1.1 change logs
### 4.0.0
Non-backward changes
* Switch file hashes from md5 to sha256
### 3.1.1
backward changes

@@ -53,3 +70,3 @@

## 3.0.0 change logs
### 3.0.0

@@ -65,3 +82,3 @@ Non-backward changes

## 2.0.0 change logs
### 2.0.0

@@ -75,3 +92,3 @@ Non-backward changes

## 1.0.0 change logs
### 1.0.0

@@ -100,2 +117,4 @@ Mostly non-backward changes

await storage.init({
// ⚠️ Watch out: The folder should only be used by node-persist and only have valid storage files.
// Otherwise you might use 'forgiveParseErrors: true'.
dir: 'relative/path/to/persist',

@@ -118,5 +137,5 @@

// in some cases, you (or some other service) might add non-valid storage files to your
// storage dir, i.e. Google Drive, make this true if you'd like to ignore these files and not throw an error
forgiveParseErrors: false,
// in some cases, you (or some other service) might add non-valid storage files to your
// storage dir, i.e. Google Drive, make this true if you'd like to ignore these files and not throw an error
forgiveParseErrors: false,

@@ -131,2 +150,6 @@ // instead of writing to file immediately, each "file" will have its own mini queue to avoid corrupted files, keep in mind that this would not properly work in multi-process setting.

writeQueueWriteOnlyLast: true,
// Limit the number of concurrently used file descriptors to avoid Error: EMFILE: too many open files
// Defaults to Infinity for maximum performance but YMMV depending on your OS and how you use the library
maxFileDescriptors: 512
});

@@ -133,0 +156,0 @@

@@ -9,5 +9,7 @@ /*

const crypto = require('crypto');
const pkg = require('../package.json');
const { nextTick } = require('process');
const pLimit = require('p-limit');
const pkg = require('../package.json');
const defaults = {

@@ -25,2 +27,3 @@ ttl: false,

writeQueueWriteOnlyLast: true,
maxFileDescriptors: Infinity,
};

@@ -132,2 +135,8 @@

}
// Update limiter if maxFileDescriptors has changed
if (!this.limit || options.maxFileDescriptors !== this.options?.maxFileDescriptors) {
this.limit = pLimit(options.maxFileDescriptors);
}
this.options = options;

@@ -313,3 +322,4 @@ },

if (currentFile[0] !== '.') {
data.push(await this.readFile(path.join(this.options.dir, currentFile)));
// Limit concurrent reads
data.push(await this.limit(() => this.readFile(path.join(this.options.dir, currentFile))));
}

@@ -330,3 +340,3 @@ }

readFile: function (file, options = {}) {
return new Promise((resolve, reject) => {
return this.limit(() => new Promise((resolve, reject) => {
fs.readFile(file, this.options.encoding, (err, text) => {

@@ -348,3 +358,3 @@ if (err) {

});
});
}));
},

@@ -420,4 +430,4 @@

writeFile: async function (file, content) {
return new Promise((resolve, reject) => {
fs.writeFile(file, this.stringify(content), this.options.encoding, async (err) => {
return this.limit(() => new Promise((resolve, reject) => {
fs.writeFile(file, this.stringify(content), this.options.encoding, (err) => {
if (err) {

@@ -429,7 +439,7 @@ return reject(err);

});
});
}));
},
deleteFile: function (file) {
return new Promise((resolve, reject) => {
return this.limit(() => new Promise((resolve, reject) => {
fs.access(file, (accessErr) => {

@@ -453,3 +463,3 @@ if (!accessErr) {

});
});
}));
},

@@ -456,0 +466,0 @@