Comparing version 0.4.3 to 0.4.4
# Disklet | ||
## 0.4.4 (2019-11-19) | ||
- Fix a race condition when writing files on Node.js. | ||
- Improve the readme file. | ||
## 0.4.3 (2019-10-23) | ||
@@ -4,0 +9,0 @@ |
@@ -340,7 +340,60 @@ 'use strict'; | ||
var Queue = | ||
/*#__PURE__*/ | ||
function () { | ||
function Queue() { | ||
this.callBackList = []; | ||
this._active = false; | ||
} | ||
var _proto = Queue.prototype; | ||
_proto.next = function next() { | ||
var _this = this; | ||
if (this._active) return; | ||
var fn = this.callBackList.shift(); | ||
if (fn == null) { | ||
if (this.onEmpty != null) { | ||
this.onEmpty(); | ||
this.onEmpty = undefined; | ||
} | ||
return; | ||
} | ||
this._active = true; | ||
fn(function () { | ||
_this._active = false; | ||
process.nextTick(function () { | ||
return _this.next(); | ||
}); | ||
}); | ||
}; | ||
return Queue; | ||
}(); | ||
var writeFilePathQueue = {}; | ||
function writeFile(path, data, opts) { | ||
return new Promise(function (resolve, reject) { | ||
return fs.writeFile(path, data, opts, function (err) { | ||
return err != null ? reject(err) : resolve(); | ||
}); | ||
var currentTask = function currentTask(onEnd) { | ||
fs.writeFile(path, data, opts, function (err) { | ||
onEnd(); | ||
err != null ? reject(err) : resolve(); | ||
}); | ||
}; | ||
if (writeFilePathQueue[path] == null) { | ||
writeFilePathQueue[path] = new Queue(); | ||
writeFilePathQueue[path].onEmpty = function () { | ||
delete writeFilePathQueue[path]; | ||
}; | ||
} | ||
writeFilePathQueue[path].callBackList.push(currentTask); | ||
writeFilePathQueue[path].next(); | ||
}); | ||
@@ -347,0 +400,0 @@ } // Helpers: ----------------------------------------------------------------- |
@@ -334,7 +334,60 @@ import { base64 } from 'rfc4648'; | ||
var Queue = | ||
/*#__PURE__*/ | ||
function () { | ||
function Queue() { | ||
this.callBackList = []; | ||
this._active = false; | ||
} | ||
var _proto = Queue.prototype; | ||
_proto.next = function next() { | ||
var _this = this; | ||
if (this._active) return; | ||
var fn = this.callBackList.shift(); | ||
if (fn == null) { | ||
if (this.onEmpty != null) { | ||
this.onEmpty(); | ||
this.onEmpty = undefined; | ||
} | ||
return; | ||
} | ||
this._active = true; | ||
fn(function () { | ||
_this._active = false; | ||
process.nextTick(function () { | ||
return _this.next(); | ||
}); | ||
}); | ||
}; | ||
return Queue; | ||
}(); | ||
var writeFilePathQueue = {}; | ||
function writeFile(path, data, opts) { | ||
return new Promise(function (resolve, reject) { | ||
return fs.writeFile(path, data, opts, function (err) { | ||
return err != null ? reject(err) : resolve(); | ||
}); | ||
var currentTask = function currentTask(onEnd) { | ||
fs.writeFile(path, data, opts, function (err) { | ||
onEnd(); | ||
err != null ? reject(err) : resolve(); | ||
}); | ||
}; | ||
if (writeFilePathQueue[path] == null) { | ||
writeFilePathQueue[path] = new Queue(); | ||
writeFilePathQueue[path].onEmpty = function () { | ||
delete writeFilePathQueue[path]; | ||
}; | ||
} | ||
writeFilePathQueue[path].callBackList.push(currentTask); | ||
writeFilePathQueue[path].next(); | ||
}); | ||
@@ -341,0 +394,0 @@ } // Helpers: ----------------------------------------------------------------- |
{ | ||
"name": "disklet", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "A tiny, composable filesystem API", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/EdgeApp/disklet", |
# Disklet | ||
[![Build Status](https://travis-ci.org/EdgeApp/disklet.svg?branch=master)](https://travis-ci.org/EdgeApp/disklet) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
> A tiny, composable filesystem API. | ||
@@ -126,3 +129,3 @@ | ||
A file's paths becomes its localStorage key, and its contents become a localStorage string value. If a `prefix` is provided via the `opts` parameter, then all localStorage keys will begin with the provided string. Binary data is transformed to base64, since localStorage can only handle strings. | ||
A file's path becomes its localStorage key, and its contents become a localStorage string value. If a `prefix` is provided via the `opts` parameter, then all localStorage keys will begin with the provided string. Binary data is transformed to base64, since localStorage can only handle strings. | ||
@@ -143,3 +146,3 @@ #### `makeMemoryFolder(storage = {}): Disklet` | ||
Creates a Disklet object with access to the phone's file system, starting at the app's documents directory. Requires [react-native-fs](https://www.npmjs.com/package/react-native-fs) to be installed & linked in the project as well. | ||
Creates a Disklet object with access to the phone's file system, starting at the app's document directory. | ||
@@ -146,0 +149,0 @@ ### Helpers |
@@ -37,2 +37,33 @@ /* global Buffer */ | ||
class Queue { | ||
private _active: boolean | ||
callBackList: Array<(onEnd: () => void) => void> | ||
onEmpty?: () => void | ||
constructor() { | ||
this.callBackList = [] | ||
this._active = false | ||
} | ||
next(): void { | ||
if (this._active) return | ||
const fn = this.callBackList.shift() | ||
if (fn == null) { | ||
if (this.onEmpty != null) { | ||
this.onEmpty() | ||
this.onEmpty = undefined | ||
} | ||
return | ||
} | ||
this._active = true | ||
fn(() => { | ||
this._active = false | ||
process.nextTick(() => this.next()) | ||
}) | ||
} | ||
} | ||
const writeFilePathQueue: { [id: string]: Queue } = {} | ||
function writeFile( | ||
@@ -43,7 +74,18 @@ path: string, | ||
): Promise<unknown> { | ||
return new Promise((resolve, reject) => | ||
fs.writeFile(path, data, opts, err => | ||
err != null ? reject(err) : resolve() | ||
) | ||
) | ||
return new Promise((resolve, reject) => { | ||
const currentTask = (onEnd: () => void): void => { | ||
fs.writeFile(path, data, opts, err => { | ||
onEnd() | ||
err != null ? reject(err) : resolve() | ||
}) | ||
} | ||
if (writeFilePathQueue[path] == null) { | ||
writeFilePathQueue[path] = new Queue() | ||
writeFilePathQueue[path].onEmpty = () => { | ||
delete writeFilePathQueue[path] | ||
} | ||
} | ||
writeFilePathQueue[path].callBackList.push(currentTask) | ||
writeFilePathQueue[path].next() | ||
}) | ||
} | ||
@@ -50,0 +92,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
410183
78
4750
201