diff options
author | Antoine du HAMEL <duhamelantoine1995@gmail.com> | 2018-03-28 19:15:52 +0200 |
---|---|---|
committer | Timothy Gu <timothygu99@gmail.com> | 2018-04-15 18:10:49 -0700 |
commit | 11819c7773d123efb8db836aefc73bde8c5f431a (patch) | |
tree | d1c9714d73e22cdde3e8ea8232168bb5305e2e33 /test | |
parent | 85e1819d8bc8fad398ac0674064a19a691ea0fd7 (diff) | |
download | node-new-11819c7773d123efb8db836aefc73bde8c5f431a.tar.gz |
fs: handle long files reading in fs.promises
PR-URL: https://github.com/nodejs/node/pull/19643
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-fs-promises-readfile.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/parallel/test-fs-promises-readfile.js b/test/parallel/test-fs-promises-readfile.js new file mode 100644 index 0000000000..1bf49503c3 --- /dev/null +++ b/test/parallel/test-fs-promises-readfile.js @@ -0,0 +1,28 @@ +'use strict'; + +const common = require('../common'); + +const assert = require('assert'); +const path = require('path'); +const { writeFile, readFile } = require('fs/promises'); +const tmpdir = require('../common/tmpdir'); +tmpdir.refresh(); + +const fn = path.join(tmpdir.path, 'large-file'); + +common.crashOnUnhandledRejection(); + +// Creating large buffer with random content +const buffer = Buffer.from( + Array.apply(null, { length: 16834 * 2 }) + .map(Math.random) + .map((number) => (number * (1 << 8))) +); + +// Writing buffer to a file then try to read it +writeFile(fn, buffer) + .then(() => readFile(fn)) + .then((readBuffer) => { + assert.strictEqual(readBuffer.equals(buffer), true); + }) + .then(common.mustCall()); |