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_ciconst tmpdir = require('../common/tmpdir'); 81cb0ef41Sopenharmony_ciconst tempFile = path.join(tmpdir.path, 'fs-non-number-arguments-throw'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_citmpdir.refresh(); 111cb0ef41Sopenharmony_cifs.writeFileSync(tempFile, 'abc\ndef'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci// A sanity check when using numbers instead of strings 141cb0ef41Sopenharmony_ciconst sanity = 'def'; 151cb0ef41Sopenharmony_ciconst saneEmitter = fs.createReadStream(tempFile, { start: 4, end: 6 }); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciassert.throws( 181cb0ef41Sopenharmony_ci () => { 191cb0ef41Sopenharmony_ci fs.createReadStream(tempFile, { start: '4', end: 6 }); 201cb0ef41Sopenharmony_ci }, 211cb0ef41Sopenharmony_ci { 221cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 231cb0ef41Sopenharmony_ci name: 'TypeError' 241cb0ef41Sopenharmony_ci }); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciassert.throws( 271cb0ef41Sopenharmony_ci () => { 281cb0ef41Sopenharmony_ci fs.createReadStream(tempFile, { start: 4, end: '6' }); 291cb0ef41Sopenharmony_ci }, 301cb0ef41Sopenharmony_ci { 311cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 321cb0ef41Sopenharmony_ci name: 'TypeError' 331cb0ef41Sopenharmony_ci }); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciassert.throws( 361cb0ef41Sopenharmony_ci () => { 371cb0ef41Sopenharmony_ci fs.createWriteStream(tempFile, { start: '4' }); 381cb0ef41Sopenharmony_ci }, 391cb0ef41Sopenharmony_ci { 401cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 411cb0ef41Sopenharmony_ci name: 'TypeError' 421cb0ef41Sopenharmony_ci }); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_cisaneEmitter.on('data', common.mustCall(function(data) { 451cb0ef41Sopenharmony_ci assert.strictEqual( 461cb0ef41Sopenharmony_ci sanity, data.toString('utf8'), 471cb0ef41Sopenharmony_ci `read ${data.toString('utf8')} instead of ${sanity}`); 481cb0ef41Sopenharmony_ci})); 49