abstract-file
Advanced tools
Comparing version 0.2.4 to 0.3.0
@@ -97,2 +97,3 @@ (function() { | ||
opts = { | ||
buffer: false, | ||
overwrite: false, | ||
@@ -99,0 +100,0 @@ highWaterMark: value._readableState.highWaterMark |
@@ -174,2 +174,5 @@ (function() { | ||
_this.contents = result; | ||
if (_this.skipSize !== aOptions.skipSize) { | ||
_this.skipSize = aOptions.skipSize; | ||
} | ||
} | ||
@@ -213,2 +216,5 @@ return done.call(_this, err, result); | ||
if (isFunction(this._loadContentSync)) { | ||
if (this.skipSize !== aOptions.skipSize) { | ||
this.skipSize = aOptions.skipSize; | ||
} | ||
return this.contents = this._loadContentSync(aOptions); | ||
@@ -308,2 +314,3 @@ } else { | ||
AbstractFile.prototype.loadContent = function(aOptions, done) { | ||
var result; | ||
if (isFunction(aOptions)) { | ||
@@ -314,10 +321,27 @@ done = aOptions; | ||
aOptions = this.getOptions(aOptions); | ||
this._loadContent(aOptions, (function(_this) { | ||
return function(err, result) { | ||
if (!(err || aOptions.overwrite === false)) { | ||
_this.contents = result; | ||
aOptions.read = true; | ||
if (!aOptions.reload && ((this.contents != null) && this.validate(aOptions, false))) { | ||
result = this.contents; | ||
if (aOptions.text && !isString(result)) { | ||
result = result.toString(); | ||
} | ||
if (aOptions.overwrite !== false) { | ||
if (this.skipSize !== aOptions.skipSize) { | ||
this.skipSize = aOptions.skipSize; | ||
} | ||
return done(err, result); | ||
}; | ||
})(this)); | ||
} | ||
done(null, result); | ||
} else { | ||
this._loadContent(aOptions, (function(_this) { | ||
return function(err, result) { | ||
if (!(err || aOptions.overwrite === false)) { | ||
_this.contents = result; | ||
if (_this.skipSize !== aOptions.skipSize) { | ||
_this.skipSize = aOptions.skipSize; | ||
} | ||
} | ||
done(err, result); | ||
}; | ||
})(this)); | ||
} | ||
return this; | ||
@@ -330,4 +354,15 @@ }; | ||
aOptions = this.getOptions(aOptions); | ||
result = this._loadContentSync(aOptions); | ||
aOptions.read = true; | ||
if (!aOptions.reload && ((this.contents != null) && this.validate(aOptions, false))) { | ||
result = this.contents; | ||
if (aOptions.text && !isString(result)) { | ||
result = result.toString(); | ||
} | ||
} else { | ||
result = this._loadContentSync(aOptions); | ||
} | ||
if (aOptions.overwrite !== false) { | ||
if (this.skipSize !== aOptions.skipSize) { | ||
this.skipSize = aOptions.skipSize; | ||
} | ||
this.contents = result; | ||
@@ -359,3 +394,3 @@ } | ||
if (aOptions.read && result && this.contents) { | ||
result = this.isStream() && !aOptions.buffer; | ||
result = this.isStream() === !(aOptions.buffer !== false); | ||
} | ||
@@ -362,0 +397,0 @@ if (raiseError && !result) { |
{ | ||
"name": "abstract-file", | ||
"description": "It can be used on any virtual file system, and stream supports.", | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/snowyu/abstract-file.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -51,2 +51,3 @@ ## abstract-file [](https://npmjs.org/package/abstract-file) | ||
* `basename` *(String)*: readonly. the basename of the `path`. | ||
* `extname` *(String)*: readonly. the extname of the `path`. | ||
@@ -65,3 +66,3 @@ | ||
* `read` *(Boolean)*: whether load file contents. defaults to false. only for `load` is true. | ||
* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to false. | ||
* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to true. | ||
only available for `load` and `read` both are true. | ||
@@ -74,3 +75,3 @@ * `text` *(Boolean)*: whether load file contents as text, defaults to false. | ||
* `read` *(Boolean)*: whether load file contents. defaults to false. | ||
* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to false. | ||
* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to true. | ||
only available for `read` is true. | ||
@@ -82,3 +83,3 @@ * `text` *(Boolean)*: whether load file contents as text, defaults to false. | ||
* `read` *(Boolean)*: whether load file contents. defaults to false. | ||
* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to false. | ||
* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to true. | ||
only available for `read` is true. | ||
@@ -89,10 +90,14 @@ * `text` *(Boolean)*: whether load file contents as text, defaults to false. | ||
* `loadContent(aOptions, done)`: Asynchronous load file contents. | ||
* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to false. | ||
* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to true. | ||
* `text` *(Boolean)*: whether load file contents as text, defaults to false. | ||
only available for `buffer` is true. | ||
* `reload` *(Boolean)*: whether force to reload the contents from the file. defaults to false. | ||
* `overwrite` *(Boolean)*: whether assign to this.contents after loading the contents from the file. defaults to true. | ||
* `done` *Function(err, content)*: the callback function. | ||
* `loadContentSync(aOptions)`: Synchronous load file contents. | ||
* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to false. | ||
* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to true. | ||
* `text` *(Boolean)*: whether load file contents as text, defaults to false. | ||
only available for `buffer` is true. | ||
* `reload` *(Boolean)*: whether force to reload the contents from the file. defaults to false. | ||
* `overwrite` *(Boolean)*: whether assign to this.contents after loading the contents from the file. defaults to true. | ||
* return contents | ||
@@ -117,2 +122,3 @@ * `getContent(aOptions, done)`: Asynchronous get the file contents buffer, skipSize used. | ||
* `toString()`: return the path. | ||
* `replaceExt(extname)`: return the replaced extname's path string. | ||
@@ -128,2 +134,12 @@ these methods should be overrides: | ||
## Changes | ||
### v0.3 | ||
* **broken** the default value of the `buffer` option is `true` now. | ||
+ add the `reload`,`overwrite` option to loadContent/loadContentSync | ||
* assign the `skipSize` from options after loading. | ||
+ add `extName` readonly property | ||
+ add `relaceExt` method to get the replaced extname's path string. | ||
## License | ||
@@ -130,0 +146,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
91534
598
142