Comparing version 1.2.1 to 1.2.2
103
chrome.js
var util = require('util') | ||
var Buffer = require('buffer').Buffer | ||
var Stream = require('stream').Stream | ||
var constants = require('constants') | ||
@@ -13,2 +14,11 @@ var Readable = Stream.Readable | ||
var O_APPEND = constants.O_APPEND || 0 | ||
var O_CREAT = constants.O_CREAT || 0 | ||
var O_EXCL = constants.O_EXCL || 0 | ||
var O_RDONLY = constants.O_RDONLY || 0 | ||
var O_RDWR = constants.O_RDWR || 0 | ||
var O_SYNC = constants.O_SYNC || 0 | ||
var O_TRUNC = constants.O_TRUNC || 0 | ||
var O_WRONLY = constants.O_WRONLY || 0 | ||
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem | ||
@@ -343,2 +353,3 @@ | ||
path = resolve(path) | ||
flags = flagToString(flags) | ||
callback = makeCallback(arguments[arguments.length - 1]) | ||
@@ -352,3 +363,3 @@ mode = modeNum(mode, 438 /*=0666*/) | ||
var opts = {} | ||
if (flags === 'w') { | ||
if (flags.indexOf('w') > -1) { | ||
opts = {create: true} | ||
@@ -362,3 +373,3 @@ } | ||
// otherwise we get the file because 'standards' | ||
if (flags === 'w') { | ||
if (flags.indexOf('w') > -1) { | ||
fileEntry.createWriter(function (fileWriter) { | ||
@@ -475,27 +486,39 @@ fileWriter.fullPath = fileEntry.fullPath | ||
var bufblob = new Blob([tmpbuf], {type: 'application/octet-binary'}) // eslint-disable-line | ||
fd.write(bufblob) | ||
window.setTimeout(callback, 0, null, tmpbuf.length) | ||
} | ||
if (util.isString(buffer)) { | ||
buffer += '' | ||
} | ||
if (!util.isFunction(position)) { | ||
if (util.isFunction(offset)) { | ||
position = offset | ||
offset = null | ||
if (fd.readyState > 0) { | ||
fd.onwriteend = function () { | ||
fd.write(blob) | ||
callback(null, buf.length) | ||
} | ||
} else { | ||
position = length | ||
fd.write(bufblob) | ||
callback(null, tmpbuf.length) | ||
} | ||
length = 'utf8' | ||
} | ||
callback = maybeCallback(position) | ||
fd.onerror = callback | ||
var blob = new Blob([buffer], {type: 'text/plain'}) // eslint-disable-line | ||
} else { | ||
if (util.isString(buffer)) { | ||
buffer += '' | ||
} | ||
if (!util.isFunction(position)) { | ||
if (util.isFunction(offset)) { | ||
position = offset | ||
offset = null | ||
} else { | ||
position = length | ||
} | ||
length = 'utf8' | ||
} | ||
callback = maybeCallback(position) | ||
fd.onerror = callback | ||
var blob = new Blob([buffer], {type: 'text/plain'}) // eslint-disable-line | ||
var buf = new Buffer(buffer) | ||
var buf = new Buffer(buffer) | ||
if (fd.readyState > 0) { | ||
fd.onwriteend = function () { | ||
if (fd.readyState > 0) { | ||
fd.onwriteend = function () { | ||
if (position !== null) { | ||
fd.seek(position) | ||
} | ||
fd.write(blob) | ||
callback(null, buf.length) | ||
} | ||
} else { | ||
if (position !== null) { | ||
@@ -507,8 +530,2 @@ fd.seek(position) | ||
} | ||
} else { | ||
if (position !== null) { | ||
fd.seek(position) | ||
} | ||
fd.write(blob) | ||
callback(null, buf.length) | ||
} | ||
@@ -900,1 +917,29 @@ } | ||
WriteStream.prototype.destroySoon = WriteStream.prototype.end | ||
function flagToString (flag) { | ||
// Only mess with strings | ||
if (util.isString(flag)) { | ||
return flag | ||
} | ||
switch (flag) { | ||
case O_RDONLY : return 'r' | ||
case O_RDONLY | O_SYNC : return 'sr' | ||
case O_RDWR : return 'r+' | ||
case O_RDWR | O_SYNC : return 'sr+' | ||
case O_TRUNC | O_CREAT | O_WRONLY : return 'w' | ||
case O_TRUNC | O_CREAT | O_WRONLY | O_EXCL : return 'xw' | ||
case O_TRUNC | O_CREAT | O_RDWR : return 'w+' | ||
case O_TRUNC | O_CREAT | O_RDWR | O_EXCL : return 'xw+' | ||
case O_APPEND | O_CREAT | O_WRONLY : return 'a' | ||
case O_APPEND | O_CREAT | O_WRONLY | O_EXCL : return 'xa' | ||
case O_APPEND | O_CREAT | O_RDWR : return 'a+' | ||
case O_APPEND | O_CREAT | O_RDWR | O_EXCL : return 'xa+' | ||
} | ||
throw new Error('Unknown file open flag: ' + flag) | ||
} |
{ | ||
"name": "chrome-fs", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Use the Node `fs` API in Chrome Apps", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
@@ -9,4 +9,4 @@ require('../simple/test-fs-stat') | ||
require('../simple/test-fs-write-buffer') | ||
require('../simple/test-fs-write-stream') | ||
// require('../simple/test-fs-empty-readStream') | ||
// require('../simple/test-fs-read-stream-fd') |
@@ -28,3 +28,3 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
filename = path.join(common.tmpDir, 'writebuffer.txt'), | ||
expected = new Buffer('hello'), | ||
expected = new Buffer('hello buffer'), | ||
openCalled = 0, | ||
@@ -31,0 +31,0 @@ writeCalled = 0 |
@@ -28,5 +28,5 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
var fn = path.join(common.tmpDir, 'write.txt') | ||
// var fn2 = path.join(common.tmpDir, 'write2.txt') | ||
var expected = 'ümlaut.' // eslint-disable-line | ||
// var constants = require('constants') | ||
var fn2 = path.join(common.tmpDir, 'write2.txt') | ||
var expected = 'ümlaut.' // eslint-disable-line | ||
var constants = require('constants') | ||
@@ -46,7 +46,6 @@ fs.open(fn, 'w', '0644', function (err, fd) { | ||
assert.equal(err, null) | ||
console.log('expected: "%s"', expected) | ||
console.log('found: "%s"', found) | ||
// assert.equal(expected, found, 'Umlaut test') | ||
assert.equal(expected, found, 'Umlaut test') | ||
fs.unlink(fn, function (err) { | ||
assert.equal(err, null) | ||
console.log('test-fs-write success 1') | ||
}) | ||
@@ -58,26 +57,26 @@ }) | ||
/* | ||
fs.open(fn2, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC, '0644', | ||
function (err, fd) { | ||
if (err) throw err | ||
console.log(err) | ||
assert.equal(err, null) | ||
console.log('open done') | ||
fs.write(fd, '', 0, 'utf8', function (err, written) { | ||
assert.equal(err, null) | ||
assert.equal(0, written) | ||
}) | ||
fs.write(fd, expected, 0, 'utf8', function (err, written) { | ||
console.log('write done') | ||
if (err) throw err | ||
assert.equal(err, null) | ||
assert.equal(Buffer.byteLength(expected), written) | ||
fs.closeSync(fd) | ||
found2 = fs.readFileSync(fn2, 'utf8') | ||
console.log('expected: "%s"', expected) | ||
console.log('found: "%s"', found2) | ||
fs.unlinkSync(fn2) | ||
fs.close(fd, function (err) { | ||
assert.equal(err, null) | ||
fs.readFile(fn2, 'utf8', function (err, found) { | ||
assert.equal(err, null) | ||
assert.equal(expected, found, 'Umlaut test') | ||
fs.unlink(fn2, function (err) { | ||
assert.equal(err, null) | ||
console.log('test-fs-write success 2') | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
process.on('exit', function () { | ||
assert.equal(expected, found) | ||
assert.equal(expected, found2) | ||
}) | ||
*/ |
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
278826
25
7898