| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dc3d70c commit a8fd01a
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -385,11 +385,14 @@ added: v10.0.0 | |||
| 385 | 385 | * `buffer` {Buffer|TypedArray|DataView} A buffer that will be filled with the | |
| 386 | 386 | file data read. | |
| 387 | 387 | * `offset` {integer} The location in the buffer at which to start filling. | |
| 388 | - * `length` {integer} The number of bytes to read. | ||
| 389 | - * `position` {integer|null} The location where to begin reading data from the | ||
| 390 | - file. If `null`, data will be read from the current file position, and | ||
| 391 | - the position will be updated. If `position` is an integer, the current | ||
| 392 | - file position will remain unchanged. | ||
| 388 | + **Default:** `0` | ||
| 389 | + * `length` {integer} The number of bytes to read. **Default:** | ||
| 390 | + `buffer.byteLength - offset` | ||
| 391 | + * `position` {integer|bigint|null} The location where to begin reading data | ||
| 392 | + from the file. If `null` or `-1`, data will be read from the current file | ||
| 393 | + position, and the position will be updated. If `position` is a non-negative | ||
| 394 | + integer, the current file position will remain unchanged. | ||
| 395 | + **Default:**: `null` | ||
| 393 | 396 | * Returns: {Promise} Fulfills upon success with an object with two properties: | |
| 394 | 397 | * `bytesRead` {integer} The number of bytes read | |
| 395 | 398 | * `buffer` {Buffer|TypedArray|DataView} A reference to the passed in `buffer` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -642,7 +642,7 @@ async function read(handle, bufferOrParams, offset, length, position) { | |||
| 642 | 642 | validateInteger(offset, 'offset', 0); | |
| 643 | 643 | } | |
| 644 | 644 | ||
| 645 | - length |= 0; | ||
| 645 | + length ??= buffer.byteLength - offset; | ||
| 646 | 646 | ||
| 647 | 647 | if (length === 0) | |
| 648 | 648 | return { __proto__: null, bytesRead: length, buffer }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ const assert = require('assert'); | |||
| 14 | 14 | const tmpDir = tmpdir.path; | |
| 15 | 15 | ||
| 16 | 16 | async function read(fileHandle, buffer, offset, length, position, options) { | |
| 17 | - return options.useConf ? | ||
| 17 | + return options?.useConf ? | ||
| 18 | 18 | fileHandle.read({ buffer, offset, length, position }) : | |
| 19 | 19 | fileHandle.read(buffer, offset, length, position); | |
| 20 | 20 | } | |
@@ -96,6 +96,21 @@ async function validateReadLength(len) { | |||
| 96 | 96 | assert.strictEqual(bytesRead, len); | |
| 97 | 97 | } | |
| 98 | 98 | ||
| 99 | + async function validateReadWithNoOptions(byte) { | ||
| 100 | + const buf = Buffer.alloc(byte); | ||
| 101 | + const filePath = fixtures.path('x.txt'); | ||
| 102 | + const fileHandle = await open(filePath, 'r'); | ||
| 103 | + let response = await fileHandle.read(buf); | ||
| 104 | + assert.strictEqual(response.bytesRead, byte); | ||
| 105 | + response = await read(fileHandle, buf, 0, undefined, 0); | ||
| 106 | + assert.strictEqual(response.bytesRead, byte); | ||
| 107 | + response = await read(fileHandle, buf, 0, null, 0); | ||
| 108 | + assert.strictEqual(response.bytesRead, byte); | ||
| 109 | + response = await read(fileHandle, buf, 0, undefined, 0, { useConf: true }); | ||
| 110 | + assert.strictEqual(response.bytesRead, byte); | ||
| 111 | + response = await read(fileHandle, buf, 0, null, 0, { useConf: true }); | ||
| 112 | + assert.strictEqual(response.bytesRead, byte); | ||
| 113 | + } | ||
| 99 | 114 | ||
| 100 | 115 | (async function() { | |
| 101 | 116 | tmpdir.refresh(); | |
@@ -109,4 +124,6 @@ async function validateReadLength(len) { | |||
| 109 | 124 | await validateReadWithPositionZero(); | |
| 110 | 125 | await validateReadLength(0); | |
| 111 | 126 | await validateReadLength(1); | |
| 127 | + await validateReadWithNoOptions(0); | ||
| 128 | + await validateReadWithNoOptions(1); | ||
| 112 | 129 | })().then(common.mustCall()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments