2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-01-13 21:42:45 +01:00
|
|
|
const common = require('../common');
|
2016-07-18 22:33:42 +02:00
|
|
|
const assert = require('assert');
|
2016-01-13 21:42:45 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const dirName = path.resolve(common.fixturesDir, 'test-readfile-unlink');
|
|
|
|
const fileName = path.resolve(dirName, 'test.bin');
|
2016-09-24 23:09:26 +02:00
|
|
|
const buf = Buffer.alloc(512 * 1024, 42);
|
2012-04-06 02:54:33 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
fs.mkdirSync(dirName);
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore if the directory already exists.
|
2016-09-24 23:09:26 +02:00
|
|
|
if (e.code !== 'EEXIST') throw e;
|
2012-04-06 02:54:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFileSync(fileName, buf);
|
|
|
|
|
|
|
|
fs.readFile(fileName, function(err, data) {
|
|
|
|
assert.ifError(err);
|
2016-09-24 23:09:26 +02:00
|
|
|
assert.strictEqual(data.length, buf.length);
|
2012-04-06 02:54:33 +02:00
|
|
|
assert.strictEqual(buf[0], 42);
|
|
|
|
|
|
|
|
fs.unlinkSync(fileName);
|
|
|
|
fs.rmdirSync(dirName);
|
|
|
|
});
|