summaryrefslogtreecommitdiff
path: root/test/simple/test-fs-read-buffer.js
diff options
context:
space:
mode:
authorFelix Geisendörfer <felix@debuggable.com>2010-05-20 18:13:22 -0400
committerRyan Dahl <ry@tinyclouds.org>2010-05-20 15:25:49 -0700
commitcbbf9e43d1770047e98fe65d5f710815f432a5b4 (patch)
treeb715eba9318b0655fd7a54cffabeff918d6856f0 /test/simple/test-fs-read-buffer.js
parentcbd2c3945b1df5b538d9e257646f604d9189601c (diff)
downloadnodejs-cbbf9e43d1770047e98fe65d5f710815f432a5b4.tar.gz
nodejs-cbbf9e43d1770047e98fe65d5f710815f432a5b4.tar.bz2
nodejs-cbbf9e43d1770047e98fe65d5f710815f432a5b4.zip
Deprecate string interface for fs.read()
This patch makes buffers the preferred output for fs.read() and fs.readSync(). The old string interface is still supported by converting buffers to strings dynamically. This allows to remove the C++ code for string handling which is also part of this patch.
Diffstat (limited to 'test/simple/test-fs-read-buffer.js')
-rw-r--r--test/simple/test-fs-read-buffer.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/simple/test-fs-read-buffer.js b/test/simple/test-fs-read-buffer.js
new file mode 100644
index 000000000..5a18177a4
--- /dev/null
+++ b/test/simple/test-fs-read-buffer.js
@@ -0,0 +1,25 @@
+require('../common');
+var path = require('path'),
+ Buffer = require('buffer').Buffer,
+ fs = require('fs'),
+ filepath = path.join(fixturesDir, 'x.txt'),
+ fd = fs.openSync(filepath, 'r'),
+ expected = 'xyz\n',
+ bufferAsync = new Buffer(expected.length),
+ bufferSync = new Buffer(expected.length),
+ readCalled = 0;
+
+fs.read(fd, bufferAsync, 0, expected.length, 0, function(err, bytesRead) {
+ readCalled++;
+
+ assert.equal(bytesRead, expected.length);
+ assert.deepEqual(bufferAsync, new Buffer(expected));
+});
+
+var r = fs.readSync(fd, bufferSync, 0, expected.length, 0);
+assert.deepEqual(bufferSync, new Buffer(expected));
+assert.equal(r, expected.length);
+
+process.addListener('exit', function() {
+ assert.equal(readCalled, 1);
+}); \ No newline at end of file