| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 28cbad3 commit 19d6eb9
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,13 +13,13 @@ const tmpdir = require('../common/tmpdir'); | |||
| 13 | 13 | const assert = require('assert'); | |
| 14 | 14 | const tmpDir = tmpdir.path; | |
| 15 | 15 | ||
| 16 | - async function read(fileHandle, buffer, offset, length, position) { | ||
| 17 | - return useConf ? | ||
| 16 | + async function read(fileHandle, buffer, offset, length, position, options) { | ||
| 17 | + return options.useConf ? | ||
| 18 | 18 | fileHandle.read({ buffer, offset, length, position }) : | |
| 19 | 19 | fileHandle.read(buffer, offset, length, position); | |
| 20 | 20 | } | |
| 21 | 21 | ||
| 22 | - async function validateRead(data, file) { | ||
| 22 | + async function validateRead(data, file, options) { | ||
| 23 | 23 | const filePath = path.resolve(tmpDir, file); | |
| 24 | 24 | const buffer = Buffer.from(data, 'utf8'); | |
| 25 | 25 | ||
@@ -31,7 +31,8 @@ async function validateRead(data, file) { | |||
| 31 | 31 | fs.closeSync(fd); | |
| 32 | 32 | ||
| 33 | 33 | fileHandle.on('close', common.mustCall()); | |
| 34 | - const readAsyncHandle = await read(fileHandle, Buffer.alloc(11), 0, 11, 0); | ||
| 34 | + const readAsyncHandle = | ||
| 35 | + await read(fileHandle, Buffer.alloc(11), 0, 11, 0, options); | ||
| 35 | 36 | assert.deepStrictEqual(data.length, readAsyncHandle.bytesRead); | |
| 36 | 37 | if (data.length) | |
| 37 | 38 | assert.deepStrictEqual(buffer, readAsyncHandle.buffer); | |
@@ -47,28 +48,26 @@ async function validateRead(data, file) { | |||
| 47 | 48 | await streamFileHandle.close(); | |
| 48 | 49 | } | |
| 49 | 50 | ||
| 50 | - async function validateLargeRead() { | ||
| 51 | + async function validateLargeRead(options) { | ||
| 51 | 52 | // Reading beyond file length (3 in this case) should return no data. | |
| 52 | 53 | // This is a test for a bug where reads > uint32 would return data | |
| 53 | 54 | // from the current position in the file. | |
| 54 | 55 | const filePath = fixtures.path('x.txt'); | |
| 55 | 56 | const fileHandle = await open(filePath, 'r'); | |
| 56 | 57 | const pos = 0xffffffff + 1; // max-uint32 + 1 | |
| 57 | - const readHandle = await read(fileHandle, Buffer.alloc(1), 0, 1, pos); | ||
| 58 | + const readHandle = | ||
| 59 | + await read(fileHandle, Buffer.alloc(1), 0, 1, pos, options); | ||
| 58 | 60 | ||
| 59 | 61 | assert.strictEqual(readHandle.bytesRead, 0); | |
| 60 | 62 | } | |
| 61 | 63 | ||
| 62 | - let useConf = false; | ||
| 63 | 64 | ||
| 64 | 65 | (async function() { | |
| 65 | - for (const value of [false, true]) { | ||
| 66 | - tmpdir.refresh(); | ||
| 67 | - useConf = value; | ||
| 68 | - | ||
| 69 | - await validateRead('Hello world', 'tmp-read-file.txt') | ||
| 70 | - .then(validateRead('', 'tmp-read-empty-file.txt')) | ||
| 71 | - .then(validateLargeRead) | ||
| 72 | - .then(common.mustCall()); | ||
| 73 | - } | ||
| 66 | + tmpdir.refresh(); | ||
| 67 | + await validateRead('Hello world', 'read-file', { useConf: false }); | ||
| 68 | + await validateRead('', 'read-empty-file', { useConf: false }); | ||
| 69 | + await validateRead('Hello world', 'read-file-conf', { useConf: true }); | ||
| 70 | + await validateRead('', 'read-empty-file-conf', { useConf: true }); | ||
| 71 | + await validateLargeRead({ useConf: false }); | ||
| 72 | + await validateLargeRead({ useConf: true }); | ||
| 74 | 73 | })().then(common.mustCall()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments