• 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');
7const tmpdir = require('../common/tmpdir');
8const tempFile = path.join(tmpdir.path, 'fs-non-number-arguments-throw');
9
10tmpdir.refresh();
11fs.writeFileSync(tempFile, 'abc\ndef');
12
13// A sanity check when using numbers instead of strings
14const sanity = 'def';
15const saneEmitter = fs.createReadStream(tempFile, { start: 4, end: 6 });
16
17assert.throws(
18  () => {
19    fs.createReadStream(tempFile, { start: '4', end: 6 });
20  },
21  {
22    code: 'ERR_INVALID_ARG_TYPE',
23    name: 'TypeError'
24  });
25
26assert.throws(
27  () => {
28    fs.createReadStream(tempFile, { start: 4, end: '6' });
29  },
30  {
31    code: 'ERR_INVALID_ARG_TYPE',
32    name: 'TypeError'
33  });
34
35assert.throws(
36  () => {
37    fs.createWriteStream(tempFile, { start: '4' });
38  },
39  {
40    code: 'ERR_INVALID_ARG_TYPE',
41    name: 'TypeError'
42  });
43
44saneEmitter.on('data', common.mustCall(function(data) {
45  assert.strictEqual(
46    sanity, data.toString('utf8'),
47    `read ${data.toString('utf8')} instead of ${sanity}`);
48}));
49