Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

filekv

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filekv - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

73

index.js

@@ -24,2 +24,6 @@ /**

var _getDataFileSubDir = function(md5key){
return md5key[0]+md5key[1]+md5key[2]+'/'+md5key[3]+md5key[4]+md5key[5];
}
var filekv = function(opt){

@@ -30,4 +34,27 @@ var self = this;

};
filekv.prototype.tool = function(){};
filekv.prototype.tool.mkdirs = function(dir,mode,cb){
var self = this;
if('function' == typeof mode){
cb = mode;
mode = '0777';
}
cb = cb || function(){};
var fs = require('fs');
var path = require('path');
fs.exists(dir,function(exists){
if(exists){
cb(null,dir);
}else{
self.mkdirs(path.dirname(dir),mode,function(){
fs.mkdir(dir,mode,cb);
});
}
});
};
filekv.prototype.setFileDir = function(path){

@@ -40,2 +67,3 @@ var self = this;

filekv.prototype.has = function(key,opt,cb){
var self = this;
if('function' == typeof opt){

@@ -47,3 +75,3 @@ cb = opt;

var md5key = md5(key);
var filePath = this.fileDir+'/'+md5key+'.fkv';
var filePath = this.fileDir+'/'+_getDataFileSubDir(md5key)+'/'+md5key+'.fkv';
fs.exists(filePath,function(exists){

@@ -58,2 +86,3 @@ if(exists){

filekv.prototype.get = function(key,opt,cb){

@@ -68,3 +97,3 @@ var self = this;

var md5key = md5(key);
var filePath = this.fileDir+'/'+md5key+'.fkv';
var filePath = this.fileDir+'/'+_getDataFileSubDir(md5key)+'/'+md5key+'.fkv';
var valueData = null;

@@ -76,3 +105,2 @@ var createTime = 0;

expireTime = _parseInt(lineData+'');
if(expireTime>0 && expireTime<=_parseInt(Date.now()/1000)){

@@ -83,11 +111,11 @@ self.del(key);

}
}else if(lineNum==1){
createTime = _parseInt(lineData+'');
}else if(lineNum==2){ //data
try{
valueData = JSON.parse(lineData+'');
valueData = JSON.parse(lineData+'', function(key, value) {
return value && value.type === 'Buffer'
? new Buffer(value.data)
: value; // Buffer类型特殊处理
});
}catch(ex){

@@ -97,5 +125,3 @@ cb(ex);

}
}
},function(err,endType,nowLineNum){

@@ -113,2 +139,3 @@ // console.log(arguments)

filekv.prototype.set = function(key,value,expireTime,opt,cb){
var self = this;
if('function' == typeof expireTime){

@@ -126,13 +153,17 @@ cb = expireTime;

var md5key = md5(key);
var filePath = this.fileDir+'/'+md5key+'.fkv';
var valueData = null;
var createTime = _parseInt(Date.now()/1000);
expireTime = _parseInt(expireTime);
var fileData = '';
fileData += expireTime+'\n';
fileData += createTime+'\n';
fileData += JSON.stringify(value);
var filePath = this.fileDir+'/'+_getDataFileSubDir(md5key)+'/';
fs.writeFile(filePath,fileData,cb)
self.tool.mkdirs(filePath,function(){
var fileAllPath = filePath+'/'+md5key+'.fkv';
var valueData = null;
var createTime = _parseInt(Date.now()/1000);
expireTime = _parseInt(expireTime);
var fileData = '';
fileData += expireTime+'\n';
fileData += createTime+'\n';
fileData += JSON.stringify(value);
fs.writeFile(fileAllPath,fileData,cb)
});
};

@@ -148,3 +179,3 @@

var md5key = md5(key);
var filePath = this.fileDir+'/'+md5key+'.fkv';
var filePath = this.fileDir+'/'+_getDataFileSubDir(md5key)+'/'+md5key+'.fkv';
fs.unlink(filePath,cb);

@@ -154,2 +185,2 @@ };

module.exports = filekv;
module.exports = filekv;
{
"name": "filekv",
"version": "1.0.0",
"description": "This is a use file system storage String/JSON data for key&value storage system",
"version": "1.0.1",
"description": "This is a key&value storage library which uses file system to store data.",
"main": "index.js",

@@ -6,0 +6,0 @@ "directories": {

# filekv
This is a use file system storage String/JSON data for key&amp;value storage system
This is a key&value storage library which uses file system to store data.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc