mirror of https://github.com/lukechilds/node.git
Browse Source
It is a maintenance burden that was removed from the docs in 2010 (v6c93e0aaf06
) and runtime-deprecated in v6.0 (1124de2d76
). PR-URL: https://github.com/nodejs/node/pull/9683 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Nikolai Vavilov
8 years ago
committed by
GitHub
7 changed files with 57 additions and 218 deletions
@ -1,64 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
const common = require('../common'); |
|||
|
|||
if (!common.enoughTestMem) { |
|||
const skipMessage = 'intensive toString tests due to memory confinements'; |
|||
common.skip(skipMessage); |
|||
return; |
|||
} |
|||
|
|||
const assert = require('assert'); |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
const Buffer = require('buffer').Buffer; |
|||
const kStringMaxLength = process.binding('buffer').kStringMaxLength; |
|||
|
|||
var fd; |
|||
|
|||
common.refreshTmpDir(); |
|||
|
|||
const file = path.join(common.tmpDir, 'toobig2.txt'); |
|||
const stream = fs.createWriteStream(file, { |
|||
flags: 'a' |
|||
}); |
|||
|
|||
const size = kStringMaxLength / 200; |
|||
const a = Buffer.alloc(size, 'a'); |
|||
|
|||
for (var i = 0; i < 201; i++) { |
|||
stream.write(a); |
|||
} |
|||
|
|||
stream.end(); |
|||
stream.on('finish', common.mustCall(function() { |
|||
fd = fs.openSync(file, 'r'); |
|||
fs.read(fd, kStringMaxLength + 1, 0, 'utf8', common.mustCall(function(err) { |
|||
assert.ok(err instanceof Error); |
|||
assert.strictEqual('"toString()" failed', err.message); |
|||
})); |
|||
})); |
|||
|
|||
function destroy() { |
|||
try { |
|||
// Make sure we close fd and unlink the file
|
|||
fs.closeSync(fd); |
|||
fs.unlinkSync(file); |
|||
} catch (err) { |
|||
// it may not exist
|
|||
} |
|||
} |
|||
|
|||
process.on('exit', destroy); |
|||
|
|||
process.on('SIGINT', function() { |
|||
destroy(); |
|||
process.exit(); |
|||
}); |
|||
|
|||
// To make sure we don't leave a very large file
|
|||
// on test machines in the event this test fails.
|
|||
process.on('uncaughtException', function(err) { |
|||
destroy(); |
|||
throw err; |
|||
}); |
@ -1,19 +0,0 @@ |
|||
'use strict'; |
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const path = require('path'); |
|||
const Buffer = require('buffer').Buffer; |
|||
const fs = require('fs'); |
|||
const filepath = path.join(common.fixturesDir, 'x.txt'); |
|||
const fd = fs.openSync(filepath, 'r'); |
|||
const bufferAsync = Buffer.alloc(0); |
|||
const bufferSync = Buffer.alloc(0); |
|||
|
|||
fs.read(fd, bufferAsync, 0, 0, 0, common.mustCall(function(err, bytesRead) { |
|||
assert.equal(bytesRead, 0); |
|||
assert.deepStrictEqual(bufferAsync, Buffer.alloc(0)); |
|||
})); |
|||
|
|||
const r = fs.readSync(fd, bufferSync, 0, 0, 0); |
|||
assert.deepStrictEqual(bufferSync, Buffer.alloc(0)); |
|||
assert.equal(r, 0); |
@ -1,35 +0,0 @@ |
|||
'use strict'; |
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const path = require('path'); |
|||
const Buffer = require('buffer').Buffer; |
|||
const fs = require('fs'); |
|||
const filepath = path.join(common.fixturesDir, 'x.txt'); |
|||
const fd = fs.openSync(filepath, 'r'); |
|||
|
|||
const expected = Buffer.from('xyz\n'); |
|||
|
|||
function test(bufferAsync, bufferSync, expected) { |
|||
fs.read(fd, |
|||
bufferAsync, |
|||
0, |
|||
expected.length, |
|||
0, |
|||
common.mustCall((err, bytesRead) => { |
|||
assert.ifError(err); |
|||
assert.strictEqual(bytesRead, expected.length); |
|||
assert.deepStrictEqual(bufferAsync, Buffer.from(expected)); |
|||
})); |
|||
|
|||
const r = fs.readSync(fd, bufferSync, 0, expected.length, 0); |
|||
assert.deepStrictEqual(bufferSync, Buffer.from(expected)); |
|||
assert.strictEqual(r, expected.length); |
|||
} |
|||
|
|||
test(Buffer.allocUnsafe(expected.length), |
|||
Buffer.allocUnsafe(expected.length), |
|||
expected); |
|||
|
|||
test(new Uint8Array(expected.length), |
|||
new Uint8Array(expected.length), |
|||
Uint8Array.from(expected)); |
@ -0,0 +1,21 @@ |
|||
'use strict'; |
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const path = require('path'); |
|||
const fs = require('fs'); |
|||
const filepath = path.join(common.fixturesDir, 'x.txt'); |
|||
const fd = fs.openSync(filepath, 'r'); |
|||
const expected = 'xyz\n'; |
|||
|
|||
// Error must be thrown with string
|
|||
assert.throws(() => { |
|||
fs.read(fd, |
|||
expected.length, |
|||
0, |
|||
'utf-8', |
|||
() => {}); |
|||
}, /Second argument needs to be a buffer/); |
|||
|
|||
assert.throws(() => { |
|||
fs.readSync(fd, expected.length, 0, 'utf-8'); |
|||
}, /Second argument needs to be a buffer/); |
Loading…
Reference in new issue