| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,26 +33,33 @@ async function testInvalid(dest, expectedCode, ...params) { | |||
| 33 | 33 | async function testValid(dest, buffer, options) { | |
| 34 | 34 | const length = options?.length; | |
| 35 | 35 | const offset = options?.offset; | |
| 36 | - let fh; | ||
| 37 | - try { | ||
| 38 | - fh = await fsPromises.open(dest, 'w+'); | ||
| 39 | - const writeResult = await fh.write(buffer, options); | ||
| 40 | - const writeBufCopy = Uint8Array.prototype.slice.call(writeResult.buffer); | ||
| 36 | + let fh, writeResult, writeBufCopy, readResult, readBufCopy; | ||
| 41 | 37 | ||
| 42 | - const readResult = await fh.read(buffer, options); | ||
| 43 | - const readBufCopy = Uint8Array.prototype.slice.call(readResult.buffer); | ||
| 38 | + try { | ||
| 39 | + fh = await fsPromises.open(dest, 'w'); | ||
| 40 | + writeResult = await fh.write(buffer, options); | ||
| 41 | + writeBufCopy = Uint8Array.prototype.slice.call(writeResult.buffer); | ||
| 42 | + } finally { | ||
| 43 | + await fh?.close(); | ||
| 44 | + } | ||
| 44 | 45 | ||
| 45 | - assert.ok(writeResult.bytesWritten >= readResult.bytesRead); | ||
| 46 | - if (length !== undefined && length !== null) { | ||
| 47 | - assert.strictEqual(writeResult.bytesWritten, length); | ||
| 48 | - } | ||
| 49 | - if (offset === undefined || offset === 0) { | ||
| 50 | - assert.deepStrictEqual(writeBufCopy, readBufCopy); | ||
| 51 | - } | ||
| 52 | - assert.deepStrictEqual(writeResult.buffer, readResult.buffer); | ||
| 46 | + try { | ||
| 47 | + fh = await fsPromises.open(dest, 'r'); | ||
| 48 | + readResult = await fh.read(buffer, options); | ||
| 49 | + readBufCopy = Uint8Array.prototype.slice.call(readResult.buffer); | ||
| 53 | 50 | } finally { | |
| 54 | 51 | await fh?.close(); | |
| 55 | 52 | } | |
| 53 | + | ||
| 54 | + assert.ok(writeResult.bytesWritten >= readResult.bytesRead); | ||
| 55 | + if (length !== undefined && length !== null) { | ||
| 56 | + assert.strictEqual(writeResult.bytesWritten, length); | ||
| 57 | + assert.strictEqual(readResult.bytesRead, length); | ||
| 58 | + } | ||
| 59 | + if (offset === undefined || offset === 0) { | ||
| 60 | + assert.deepStrictEqual(writeBufCopy, readBufCopy); | ||
| 61 | + } | ||
| 62 | + assert.deepStrictEqual(writeResult.buffer, readResult.buffer); | ||
| 56 | 63 | } | |
| 57 | 64 | ||
| 58 | 65 | (async () => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,22 +29,26 @@ function testValidCb(buffer, options, index, callback) { | |||
| 29 | 29 | const length = options?.length; | |
| 30 | 30 | const offset = options?.offset; | |
| 31 | 31 | const dest = path.resolve(tmpdir.path, `rwopt_valid_${index}`); | |
| 32 | - fs.open(dest, 'w+', common.mustSucceed((fd) => { | ||
| 32 | + fs.open(dest, 'w', common.mustSucceed((fd) => { | ||
| 33 | 33 | fs.write(fd, buffer, options, common.mustSucceed((bytesWritten, bufferWritten) => { | |
| 34 | 34 | const writeBufCopy = Uint8Array.prototype.slice.call(bufferWritten); | |
| 35 | - | ||
| 36 | - fs.read(fd, buffer, options, common.mustSucceed((bytesRead, bufferRead) => { | ||
| 37 | - const readBufCopy = Uint8Array.prototype.slice.call(bufferRead); | ||
| 38 | - | ||
| 39 | - assert.ok(bytesWritten >= bytesRead); | ||
| 40 | - if (length !== undefined && length !== null) { | ||
| 41 | - assert.strictEqual(bytesWritten, length); | ||
| 42 | - } | ||
| 43 | - if (offset === undefined || offset === 0) { | ||
| 44 | - assert.deepStrictEqual(writeBufCopy, readBufCopy); | ||
| 45 | - } | ||
| 46 | - assert.deepStrictEqual(bufferWritten, bufferRead); | ||
| 47 | - fs.close(fd, common.mustSucceed(callback)); | ||
| 35 | + fs.close(fd, common.mustSucceed(() => { | ||
| 36 | + fs.open(dest, 'r', common.mustSucceed((fd) => { | ||
| 37 | + fs.read(fd, buffer, options, common.mustSucceed((bytesRead, bufferRead) => { | ||
| 38 | + const readBufCopy = Uint8Array.prototype.slice.call(bufferRead); | ||
| 39 | + | ||
| 40 | + assert.ok(bytesWritten >= bytesRead); | ||
| 41 | + if (length !== undefined && length !== null) { | ||
| 42 | + assert.strictEqual(bytesWritten, length); | ||
| 43 | + assert.strictEqual(bytesRead, length); | ||
| 44 | + } | ||
| 45 | + if (offset === undefined || offset === 0) { | ||
| 46 | + assert.deepStrictEqual(writeBufCopy, readBufCopy); | ||
| 47 | + } | ||
| 48 | + assert.deepStrictEqual(bufferWritten, bufferRead); | ||
| 49 | + fs.close(fd, common.mustSucceed(callback)); | ||
| 50 | + })); | ||
| 51 | + })); | ||
| 48 | 52 | })); | |
| 49 | 53 | })); | |
| 50 | 54 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,19 +32,27 @@ function testInvalid(dest, expectedCode, ...bufferAndOptions) { | |||
| 32 | 32 | ||
| 33 | 33 | function testValid(dest, buffer, options) { | |
| 34 | 34 | const length = options?.length; | |
| 35 | - let fd; | ||
| 35 | + let fd, bytesWritten, bytesRead; | ||
| 36 | + | ||
| 36 | 37 | try { | |
| 37 | - fd = fs.openSync(dest, 'w+'); | ||
| 38 | - const bytesWritten = fs.writeSync(fd, buffer, options); | ||
| 39 | - const bytesRead = fs.readSync(fd, buffer, options); | ||
| 38 | + fd = fs.openSync(dest, 'w'); | ||
| 39 | + bytesWritten = fs.writeSync(fd, buffer, options); | ||
| 40 | + } finally { | ||
| 41 | + if (fd != null) fs.closeSync(fd); | ||
| 42 | + } | ||
| 40 | 43 | ||
| 41 | - assert.ok(bytesWritten >= bytesRead); | ||
| 42 | - if (length !== undefined && length !== null) { | ||
| 43 | - assert.strictEqual(bytesWritten, length); | ||
| 44 | - } | ||
| 44 | + try { | ||
| 45 | + fd = fs.openSync(dest, 'r'); | ||
| 46 | + bytesRead = fs.readSync(fd, buffer, options); | ||
| 45 | 47 | } finally { | |
| 46 | 48 | if (fd != null) fs.closeSync(fd); | |
| 47 | 49 | } | |
| 50 | + | ||
| 51 | + assert.ok(bytesWritten >= bytesRead); | ||
| 52 | + if (length !== undefined && length !== null) { | ||
| 53 | + assert.strictEqual(bytesWritten, length); | ||
| 54 | + assert.strictEqual(bytesRead, length); | ||
| 55 | + } | ||
| 48 | 56 | } | |
| 49 | 57 | ||
| 50 | 58 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments