2014-01-21 21:25:09 +00:00
|
|
|
define(["Filer", "util"], function(Filer, util) {
|
2013-11-27 17:18:09 +00:00
|
|
|
|
|
|
|
describe('fs.write', function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2013-11-27 17:18:09 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
expect(fs.write).to.be.a('function');
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should write data to a file', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile', 'w', function(error, fd) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.equal(buffer.length);
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfile', function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result.type).to.equal('FILE');
|
|
|
|
expect(result.size).to.equal(buffer.length);
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should update the current file position', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
2014-01-21 21:25:09 +00:00
|
|
|
var _result = 0;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile', 'w', function(error, fd) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
_result += result;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
_result += result;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfile', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(_result).to.equal(2 * buffer.length);
|
|
|
|
expect(result.size).to.equal(_result);
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|