v0.0.13
This commit is contained in:
parent
26742e635b
commit
1abc0d4f86
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "filer",
|
"name": "filer",
|
||||||
"version": "0.0.12",
|
"version": "0.0.13",
|
||||||
"main": "dist/filer.js",
|
"main": "dist/filer.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "1.17.1",
|
"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)
|
* Update node times. Only passed times are modified (undefined times are ignored)
|
||||||
* and filesystem flags are examined in order to override update logic.
|
* 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) {
|
if(error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
} else {
|
} 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 _position = (!(undefined === position || null === position)) ? position : ofd.position;
|
||||||
var newSize = Math.max(fileData.length, _position + length);
|
var newSize = Math.max(fileData.length, _position + length);
|
||||||
var newData = new Buffer(newSize);
|
var newData = new Buffer(newSize);
|
||||||
|
@ -12946,7 +12976,10 @@ function read_data(context, ofd, buffer, offset, length, position, callback) {
|
||||||
if(error) {
|
if(error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
} else {
|
} 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 _position = (!(undefined === position || null === position)) ? position : ofd.position;
|
||||||
length = (_position + length > buffer.length) ? length - _position : length;
|
length = (_position + length > buffer.length) ? length - _position : length;
|
||||||
fileData.copy(buffer, offset, _position, _position + length);
|
fileData.copy(buffer, offset, _position, _position + length);
|
||||||
|
@ -13333,6 +13366,10 @@ function truncate_file(context, path, length, callback) {
|
||||||
if (error) {
|
if (error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
} else {
|
} else {
|
||||||
|
fileData = ensureBuffer(fileData);
|
||||||
|
if(!fileData) {
|
||||||
|
return callback(new Errors.EIO('Expected Buffer'));
|
||||||
|
}
|
||||||
var data = new Buffer(length);
|
var data = new Buffer(length);
|
||||||
data.fill(0);
|
data.fill(0);
|
||||||
if(fileData) {
|
if(fileData) {
|
||||||
|
@ -13387,6 +13424,10 @@ function ftruncate_file(context, ofd, length, callback) {
|
||||||
callback(error);
|
callback(error);
|
||||||
} else {
|
} else {
|
||||||
var data;
|
var data;
|
||||||
|
fileData = ensureBuffer(fileData);
|
||||||
|
if(!fileData) {
|
||||||
|
return callback(new Errors.EIO('Expected Buffer'));
|
||||||
|
}
|
||||||
if(fileData) {
|
if(fileData) {
|
||||||
data = fileData.slice(0, length);
|
data = fileData.slice(0, length);
|
||||||
} else {
|
} else {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -11,7 +11,7 @@
|
||||||
"idb",
|
"idb",
|
||||||
"websql"
|
"websql"
|
||||||
],
|
],
|
||||||
"version": "0.0.12",
|
"version": "0.0.13",
|
||||||
"author": "Alan K <ack@modeswitch.org> (http://blog.modeswitch.org)",
|
"author": "Alan K <ack@modeswitch.org> (http://blog.modeswitch.org)",
|
||||||
"homepage": "http://js-platform.github.io/filer",
|
"homepage": "http://js-platform.github.io/filer",
|
||||||
"bugs": "https://github.com/js-platform/filer/issues",
|
"bugs": "https://github.com/js-platform/filer/issues",
|
||||||
|
|
Loading…
Reference in New Issue