11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst fs = require('fs');
61cb0ef41Sopenharmony_ciconst path = require('path');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciif (!common.isWindows)
91cb0ef41Sopenharmony_ci  common.skip('This test is for Windows only.');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
121cb0ef41Sopenharmony_citmpdir.refresh();
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst DATA_VALUE = 'hello';
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci// Refs: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
171cb0ef41Sopenharmony_ci// Ignore '/', '\\' and ':'
181cb0ef41Sopenharmony_ciconst RESERVED_CHARACTERS = '<>"|?*';
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci[...RESERVED_CHARACTERS].forEach((ch) => {
211cb0ef41Sopenharmony_ci  const pathname = path.join(tmpdir.path, `somefile_${ch}`);
221cb0ef41Sopenharmony_ci  assert.throws(
231cb0ef41Sopenharmony_ci    () => {
241cb0ef41Sopenharmony_ci      fs.writeFileSync(pathname, DATA_VALUE);
251cb0ef41Sopenharmony_ci    },
261cb0ef41Sopenharmony_ci    /^Error: ENOENT: no such file or directory, open '.*'$/,
271cb0ef41Sopenharmony_ci    `failed with '${ch}'`);
281cb0ef41Sopenharmony_ci});
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci// Test for ':' (NTFS data streams).
311cb0ef41Sopenharmony_ci// Refs: https://msdn.microsoft.com/en-us/library/windows/desktop/bb540537.aspx
321cb0ef41Sopenharmony_ciconst pathname = path.join(tmpdir.path, 'foo:bar');
331cb0ef41Sopenharmony_cifs.writeFileSync(pathname, DATA_VALUE);
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_cilet content = '';
361cb0ef41Sopenharmony_ciconst fileDataStream = fs.createReadStream(pathname, {
371cb0ef41Sopenharmony_ci  encoding: 'utf8'
381cb0ef41Sopenharmony_ci});
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cifileDataStream.on('data', (data) => {
411cb0ef41Sopenharmony_ci  content += data;
421cb0ef41Sopenharmony_ci});
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_cifileDataStream.on('end', common.mustCall(() => {
451cb0ef41Sopenharmony_ci  assert.strictEqual(content, DATA_VALUE);
461cb0ef41Sopenharmony_ci}));
47