-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: add
FileHandle.prototype.readLines
PR-URL: #42590 Reviewed-By: LiviaMedeiros <livia@cirno.name>
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import '../common/index.mjs'; | ||
import tmpdir from '../common/tmpdir.js'; | ||
|
||
import assert from 'node:assert'; | ||
import { open, writeFile } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
|
||
tmpdir.refresh(); | ||
|
||
const filePath = path.join(tmpdir.path, 'file.txt'); | ||
|
||
await writeFile(filePath, '1\n\n2\n'); | ||
|
||
let file; | ||
try { | ||
file = await open(filePath); | ||
|
||
let i = 0; | ||
for await (const line of file.readLines()) { | ||
switch (i++) { | ||
case 0: | ||
assert.strictEqual(line, '1'); | ||
break; | ||
|
||
case 1: | ||
assert.strictEqual(line, ''); | ||
break; | ||
|
||
case 2: | ||
assert.strictEqual(line, '2'); | ||
break; | ||
|
||
default: | ||
assert.fail(); | ||
break; | ||
} | ||
} | ||
} finally { | ||
await file?.close(); | ||
} |