Comparing version 1.2.3 to 2.0.0
130
chrome.js
@@ -11,4 +11,2 @@ var util = require('util') | ||
var DEBUG = true | ||
var kMinPoolSpace = 128 | ||
var pool | ||
@@ -26,7 +24,2 @@ var O_APPEND = constants.O_APPEND || 0 | ||
function allocNewPool (poolSize) { | ||
pool = new Buffer(poolSize) | ||
pool.used = 0 | ||
} | ||
function nullCheck (path, callback) { | ||
@@ -81,2 +74,7 @@ if (('' + path).indexOf('\u0000') !== -1) { | ||
function resolve (path) { | ||
// Allow null pass through | ||
if (path === null) { | ||
return null | ||
} | ||
// Don't let anything but strings be passed as on | ||
if (typeof path !== 'string') { | ||
@@ -341,17 +339,2 @@ throw Error('Cannot resolve: Paths must be strings') | ||
exports.writeFile = function (path, data, options, cb) { | ||
var callback = maybeCallback(arguments[arguments.length - 1]) | ||
if (util.isFunction(options) || !options) { | ||
options = { encoding: 'utf8', mode: 438, flag: 'w' } /*=0666*/ | ||
} else if (util.isString(options)) { | ||
options = { encoding: options, mode: 438, flag: 'w' } | ||
} else if (!util.isObject(options)) { | ||
throw new TypeError('Bad arguments') | ||
} | ||
assertEncoding(options.encoding) | ||
callback() | ||
} | ||
exports.open = function (path, flags, mode, callback) { | ||
@@ -401,2 +384,6 @@ path = resolve(path) | ||
exports.read = function (fd, buffer, offset, length, position, callback) { | ||
if (fd === null) { | ||
callback(null, 0, '') | ||
return | ||
} | ||
if (!util.isBuffer(buffer)) { | ||
@@ -680,2 +667,3 @@ // fs.read(fd, expected.length, 0, 'utf-8', function (err, str, bytesRead) | ||
} | ||
// debugger // eslint-disable-line | ||
// a little bit bigger buffer and water marks by default | ||
@@ -693,4 +681,4 @@ options = util._extend({ | ||
this.start = options.hasOwnProperty('start') ? options.start : undefined | ||
this.end = options.hasOwnProperty('end') ? options.end : undefined | ||
this.start = options.hasOwnProperty('start') ? options.start : 0 | ||
this.end = options.hasOwnProperty('end') ? options.end : 0 | ||
this.autoClose = options.hasOwnProperty('autoClose') ? | ||
@@ -716,4 +704,7 @@ options.autoClose : true | ||
} | ||
if (this.fd === null) { | ||
this.pause() | ||
} | ||
if (!util.isNumber(this.fd)) { | ||
if (this.path !== null) { | ||
this.open() | ||
@@ -732,2 +723,7 @@ } | ||
var self = this | ||
if (this.flags === null) { | ||
this.flags = 'r' | ||
} | ||
exports.open(this.path, this.flags, this.mode, function (er, fd) { | ||
@@ -741,7 +737,5 @@ if (er) { | ||
} | ||
self.resume() | ||
self.fd = fd | ||
self.emit('open', fd) | ||
// start the flow of data. | ||
debugger // eslint-disable-line | ||
self.read() | ||
@@ -752,3 +746,3 @@ }) | ||
ReadStream.prototype._read = function (n) { | ||
if (!util.isNumber(this.fd)) { | ||
if (this.fd === null) { | ||
return this.once('open', function () { | ||
@@ -758,3 +752,2 @@ this._read(n) | ||
} | ||
if (this.destroyed) { | ||
@@ -764,48 +757,29 @@ return | ||
if (!pool || pool.length - pool.used < kMinPoolSpace) { | ||
// discard the old pool. | ||
pool = null | ||
allocNewPool(this._readableState.highWaterMark) | ||
if (this.ispaused) { | ||
return | ||
} | ||
// Grab another reference to the pool in the case that while we're | ||
// in the thread pool another read() finishes up the pool, and | ||
// allocates a new one. | ||
var thisPool = pool | ||
var toRead = Math.min(pool.length - pool.used, n) | ||
var start = pool.used | ||
if (!util.isUndefined(this.pos)) { | ||
toRead = Math.min(this.end - this.pos + 1, toRead) | ||
if (this.pos === this.fd.size) { | ||
return this.push(null) | ||
} | ||
// already read everything we were supposed to read! | ||
// treat as EOF. | ||
if (toRead <= 0) { | ||
this.pos = this.fd.size | ||
if (this.fd.size === 0) { | ||
return this.push(null) | ||
} | ||
// the actual read. | ||
var self = this | ||
exports.read(this.fd, pool, pool.used, toRead, this.pos, onread) | ||
// move the pool positions, and internal position for reading. | ||
if (!util.isUndefined(this.pos)) { | ||
this.pos += toRead | ||
} | ||
pool.used += toRead | ||
function onread (er, bytesRead) { | ||
if (er) { | ||
// Sketchy implementation that pushes the whole file to the the stream | ||
// But maybe fd has a size that we can iterate to? | ||
var onread = function (err, length, data) { | ||
if (err) { | ||
if (self.autoClose) { | ||
self.destroy() | ||
} | ||
self.emit('error', er) | ||
} else { | ||
var b = null | ||
if (bytesRead > 0) { | ||
b = thisPool.slice(start, start + bytesRead) | ||
} | ||
self.push(b) | ||
self.emit('error', err) | ||
} | ||
self.push(data) | ||
} | ||
exports.read(this.fd, new Buffer(this.fd.size), 0, this.fd.size, 0, onread) | ||
} | ||
@@ -819,6 +793,3 @@ | ||
this.destroyed = true | ||
if (util.isNumber(this.fd)) { | ||
this.close() | ||
} | ||
this.close() | ||
} | ||
@@ -828,23 +799,13 @@ | ||
var self = this | ||
if (cb) { | ||
this.once('close', cb) | ||
} | ||
if (this.closed || !util.isNumber(this.fd)) { | ||
if (!util.isNumber(this.fd)) { | ||
this.once('open', close) | ||
return | ||
} | ||
return process.nextTick(this.emit.bind(this, 'close')) | ||
if (this.closed) { | ||
this.emit('close') | ||
} | ||
this.closed = true | ||
close() | ||
function close (fd) { | ||
exports.close(fd || self.fd, function (er) { | ||
if (er) { | ||
self.emit('error', er) | ||
} else { | ||
self.emit('close') | ||
} | ||
}) | ||
self.emit('close') | ||
self.fd = null | ||
@@ -889,6 +850,7 @@ } | ||
} | ||
/* | ||
if (!util.isNumber(this.fd)) { | ||
this.open() | ||
} | ||
*/ | ||
// dispose on finish. | ||
@@ -895,0 +857,0 @@ this.once('finish', this.close) |
{ | ||
"name": "chrome-fs", | ||
"version": "1.2.3", | ||
"version": "2.0.0", | ||
"description": "Use the Node `fs` API in Chrome Apps", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
@@ -61,5 +61,5 @@ # chrome-fs | ||
#### Class: - fs.ReadStream | ||
- [ ] fs.ReadStream | ||
- [ ] Event: 'open' | ||
- [ ] fs.createWriteStream(path[, options]) | ||
- [x] fs.ReadStream | ||
- [x] Event: 'open' | ||
- [x] fs.createWriteStream(path[, options]) | ||
@@ -66,0 +66,0 @@ #### Class: - fs.WriteStream |
@@ -11,5 +11,5 @@ require('../simple/test-fs-stat') | ||
require('../simple/test-fs-read-buffer') | ||
require('../simple/test-fs-read-stream-fd') | ||
require('../simple/test-fs-read-stream') | ||
require('../simple/test-fs-empty-read-stream') | ||
// require('../simple/test-fs-write-stream') | ||
// require('../simple/test-fs-read-buffer') | ||
// require('../simple/test-fs-empty-readStream') | ||
// require('../simple/test-fs-read-stream-fd') |
@@ -39,3 +39,3 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
fs.rmdir(pathname, function () { | ||
console.log('mkdir 1 success') | ||
console.log('test-fs-mkdir 1 success') | ||
}) | ||
@@ -55,5 +55,5 @@ }) | ||
assert(ncalls2, 2) | ||
console.log('mkdir 2 success') | ||
console.log('test-fs-mkdir 2 success') | ||
}) | ||
}) | ||
}) |
@@ -53,5 +53,4 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
assert.equal(output, input) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is too big to display
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
310022
28
8621