summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-buffertype-writesync.js
blob: 042552a46f97b3198c75ad322774d441cd8594ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict';
require('../common');

// This test ensures that writeSync does support inputs which
// are then correctly converted into string buffers.

const assert = require('assert');
const fs = require('fs');
const path = require('path');

const tmpdir = require('../common/tmpdir');

const filePath = path.join(tmpdir.path, 'test_buffer_type');
const v = [true, false, 0, 1, Infinity, () => {}, {}, [], undefined, null];

tmpdir.refresh();

v.forEach((value) => {
  const fd = fs.openSync(filePath, 'w');
  fs.writeSync(fd, value);
  assert.strictEqual(fs.readFileSync(filePath).toString(), String(value));
  fs.closeSync(fd);
});