GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add test for fs.read when offset key is null · nodejs/node@b6aa42c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-fs-read-offset-null.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-fs-read-offset-null.js‎

Copy file name to clipboard
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
4+
// Test to assert the desired functioning of fs.read
5+
// when {offset:null} is passed as options parameter
6+
7+
const common = require('../common');
8+
const assert = require('assert');
9+
const fs = require('fs');
10+
const fsPromises = fs.promises;
11+
const fixtures = require('../common/fixtures');
12+
const filepath = fixtures.path('x.txt');
13+
14+
const buf = Buffer.alloc(1);
15+
// Reading only one character, hence buffer of one byte is enough
16+
17+
// Test for callback api
18+
fs.open(filepath, 'r', common.mustSucceed((fd) => {
19+
fs.read(fd, { offset: null, buffer: buf },
20+
common.mustSucceed((bytesRead, buffer) => {
21+
assert.strictEqual(buffer[0], 120);
22+
// Test is done by making sure the first letter in buffer is
23+
// same as first letter in file.
24+
// 66 is the hex for ascii code of letter B
25+
26+
fs.close(fd, common.mustSucceed(() => {}));
27+
}));
28+
}));
29+
30+
let filehandle = null;
31+
32+
// Test for promise api
33+
(async () => {
34+
filehandle = await fsPromises.open(filepath, 'r');
35+
const readObject = await filehandle.read(buf, null, buf.length);
36+
assert.strictEqual(readObject.buffer[0], 120);
37+
})()
38+
.then(common.mustCall())
39+
.finally(async () => {
40+
// Close the file handle if it is opened
41+
if (filehandle)
42+
await filehandle.close();
43+
});

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.