• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const fixtures = require('../common/fixtures');
5const assert = require('assert');
6const fs = require('fs');
7const path = require('path');
8
9const tmpdir = require('../common/tmpdir');
10tmpdir.refresh();
11
12fs.access(Buffer.from(tmpdir.path), common.mustSucceed());
13
14const buf = Buffer.from(path.join(tmpdir.path, 'a.txt'));
15fs.open(buf, 'w+', common.mustSucceed((fd) => {
16  assert(fd);
17  fs.close(fd, common.mustSucceed());
18}));
19
20assert.throws(
21  () => {
22    fs.accessSync(true);
23  },
24  {
25    code: 'ERR_INVALID_ARG_TYPE',
26    name: 'TypeError',
27    message: 'The "path" argument must be of type string or an instance of ' +
28             'Buffer or URL. Received type boolean (true)'
29  }
30);
31
32const dir = Buffer.from(fixtures.fixturesDir);
33fs.readdir(dir, 'hex', common.mustSucceed((hexList) => {
34  fs.readdir(dir, common.mustSucceed((stringList) => {
35    stringList.forEach((val, idx) => {
36      const fromHexList = Buffer.from(hexList[idx], 'hex').toString();
37      assert.strictEqual(
38        fromHexList,
39        val,
40        `expected ${val}, got ${fromHexList} by hex decoding ${hexList[idx]}`
41      );
42    });
43  }));
44}));
45