v0.0.13
This commit is contained in:
parent
26742e635b
commit
1abc0d4f86
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "filer",
|
||||
"version": "0.0.12",
|
||||
"version": "0.0.13",
|
||||
"main": "dist/filer.js",
|
||||
"devDependencies": {
|
||||
"mocha": "1.17.1",
|
||||
|
|
|
@ -12209,6 +12209,33 @@ function standard_check_result_cb(callback) {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce array-like data to Buffer so we can .copy(), etc.
|
||||
* Allow null, a Buffer, or an object that can be dealt with
|
||||
* by the Buffer constructor (e.g., Typed Array, Array, ...)
|
||||
*
|
||||
* WARNING: be very careful not to call this on parameters of
|
||||
* API methods that pass storage (like read). You don't want to
|
||||
* overwrite a buffer that a caller is holding a reference to,
|
||||
* and expects to be filled via the read. If the caller passes
|
||||
* in a non-Buffer, we should throw instead of coerce.
|
||||
*/
|
||||
function ensureBuffer(maybeBuffer) {
|
||||
if(!maybeBuffer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(Buffer.isBuffer(maybeBuffer)) {
|
||||
return maybeBuffer;
|
||||
}
|
||||
|
||||
try {
|
||||
return new Buffer(maybeBuffer);
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update node times. Only passed times are modified (undefined times are ignored)
|
||||
* and filesystem flags are examined in order to override update logic.
|
||||
|
@ -12906,7 +12933,10 @@ function write_data(context, ofd, buffer, offset, length, position, callback) {
|
|||
if(error) {
|
||||
callback(error);
|
||||
} else {
|
||||
fileData = result;
|
||||
fileData = ensureBuffer(result);
|
||||
if(!fileData) {
|
||||
return callback(new Errors.EIO('Expected Buffer'));
|
||||
}
|
||||
var _position = (!(undefined === position || null === position)) ? position : ofd.position;
|
||||
var newSize = Math.max(fileData.length, _position + length);
|
||||
var newData = new Buffer(newSize);
|
||||
|
@ -12946,7 +12976,10 @@ function read_data(context, ofd, buffer, offset, length, position, callback) {
|
|||
if(error) {
|
||||
callback(error);
|
||||
} else {
|
||||
fileData = result;
|
||||
fileData = ensureBuffer(result);
|
||||
if(!fileData) {
|
||||
return callback(new Errors.EIO('Expected Buffer'));
|
||||
}
|
||||
var _position = (!(undefined === position || null === position)) ? position : ofd.position;
|
||||
length = (_position + length > buffer.length) ? length - _position : length;
|
||||
fileData.copy(buffer, offset, _position, _position + length);
|
||||
|
@ -13333,6 +13366,10 @@ function truncate_file(context, path, length, callback) {
|
|||
if (error) {
|
||||
callback(error);
|
||||
} else {
|
||||
fileData = ensureBuffer(fileData);
|
||||
if(!fileData) {
|
||||
return callback(new Errors.EIO('Expected Buffer'));
|
||||
}
|
||||
var data = new Buffer(length);
|
||||
data.fill(0);
|
||||
if(fileData) {
|
||||
|
@ -13387,6 +13424,10 @@ function ftruncate_file(context, ofd, length, callback) {
|
|||
callback(error);
|
||||
} else {
|
||||
var data;
|
||||
fileData = ensureBuffer(fileData);
|
||||
if(!fileData) {
|
||||
return callback(new Errors.EIO('Expected Buffer'));
|
||||
}
|
||||
if(fileData) {
|
||||
data = fileData.slice(0, length);
|
||||
} else {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -11,7 +11,7 @@
|
|||
"idb",
|
||||
"websql"
|
||||
],
|
||||
"version": "0.0.12",
|
||||
"version": "0.0.13",
|
||||
"author": "Alan K <ack@modeswitch.org> (http://blog.modeswitch.org)",
|
||||
"homepage": "http://js-platform.github.io/filer",
|
||||
"bugs": "https://github.com/js-platform/filer/issues",
|
||||
|
|
Loading…
Reference in New Issue