| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bddb4c6 commit a5a1691
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -521,7 +521,7 @@ async function read(handle, bufferOrOptions, offset, length, position) { | |||
| 521 | 521 | } | |
| 522 | 522 | offset = bufferOrOptions.offset || 0; | |
| 523 | 523 | length = buffer.byteLength; | |
| 524 | - position = bufferOrOptions.position || null; | ||
| 524 | + position = bufferOrOptions.position ?? null; | ||
| 525 | 525 | } | |
| 526 | 526 | ||
| 527 | 527 | if (offset == null) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,6 +68,25 @@ async function validateReadNoParams() { | |||
| 68 | 68 | await fileHandle.read(); | |
| 69 | 69 | } | |
| 70 | 70 | ||
| 71 | + // Validates that the zero position is respected after the position has been | ||
| 72 | + // moved. The test iterates over the xyz chars twice making sure that the values | ||
| 73 | + // are read from the correct position. | ||
| 74 | + async function validateReadWithPositionZero() { | ||
| 75 | + const opts = { useConf: true }; | ||
| 76 | + const filePath = fixtures.path('x.txt'); | ||
| 77 | + const fileHandle = await open(filePath, 'r'); | ||
| 78 | + const expectedSequence = ['x', 'y', 'z']; | ||
| 79 | + | ||
| 80 | + for (let i = 0; i < expectedSequence.length * 2; i++) { | ||
| 81 | + const len = 1; | ||
| 82 | + const pos = i % 3; | ||
| 83 | + const buf = Buffer.alloc(len); | ||
| 84 | + const { bytesRead } = await read(fileHandle, buf, 0, len, pos, opts); | ||
| 85 | + assert.strictEqual(bytesRead, len); | ||
| 86 | + assert.strictEqual(buf.toString(), expectedSequence[pos]); | ||
| 87 | + } | ||
| 88 | + } | ||
| 89 | + | ||
| 71 | 90 | ||
| 72 | 91 | (async function() { | |
| 73 | 92 | tmpdir.refresh(); | |
@@ -78,4 +97,5 @@ async function validateReadNoParams() { | |||
| 78 | 97 | await validateLargeRead({ useConf: false }); | |
| 79 | 98 | await validateLargeRead({ useConf: true }); | |
| 80 | 99 | await validateReadNoParams(); | |
| 100 | + await validateReadWithPositionZero(); | ||
| 81 | 101 | })().then(common.mustCall()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments