• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const fs = require('fs');
6const path = require('path');
7
8if (!common.isWindows)
9  common.skip('This test is for Windows only.');
10
11const tmpdir = require('../common/tmpdir');
12tmpdir.refresh();
13
14const DATA_VALUE = 'hello';
15
16// Refs: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
17// Ignore '/', '\\' and ':'
18const RESERVED_CHARACTERS = '<>"|?*';
19
20[...RESERVED_CHARACTERS].forEach((ch) => {
21  const pathname = path.join(tmpdir.path, `somefile_${ch}`);
22  assert.throws(
23    () => {
24      fs.writeFileSync(pathname, DATA_VALUE);
25    },
26    /^Error: ENOENT: no such file or directory, open '.*'$/,
27    `failed with '${ch}'`);
28});
29
30// Test for ':' (NTFS data streams).
31// Refs: https://msdn.microsoft.com/en-us/library/windows/desktop/bb540537.aspx
32const pathname = path.join(tmpdir.path, 'foo:bar');
33fs.writeFileSync(pathname, DATA_VALUE);
34
35let content = '';
36const fileDataStream = fs.createReadStream(pathname, {
37  encoding: 'utf8'
38});
39
40fileDataStream.on('data', (data) => {
41  content += data;
42});
43
44fileDataStream.on('end', common.mustCall(() => {
45  assert.strictEqual(content, DATA_VALUE);
46}));
47