HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-172-31-4-197 6.8.0-1036-aws #38~22.04.1-Ubuntu SMP Fri Aug 22 15:44:33 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/web.enelar.com.co/node_modules/minipass-sized/test/basic.js
const t = require('tap')
const MPS = require('../')

t.test('ok if size checks out', t => {
  const mps = new MPS({ size: 4 })

  mps.write(Buffer.from('a').toString('hex'), 'hex')
  mps.write(Buffer.from('sd'))
  mps.end('f')
  return mps.concat().then(data => t.equal(data.toString(), 'asdf'))
})

t.test('error if size exceeded', t => {
  const mps = new MPS({ size: 1 })
  mps.on('error', er => {
    t.match(er, {
      message: 'Bad data size: expected 1 bytes, but got 4',
      found: 4,
      expect: 1,
      code: 'EBADSIZE',
      name: 'SizeError',
    })
    t.end()
  })
  mps.write('asdf')
})

t.test('error if size is not met', t => {
  const mps = new MPS({ size: 999 })
  t.throws(() => mps.end(), {
    message: 'Bad data size: expected 999 bytes, but got 0',
    found: 0,
    name: 'SizeError',
    expect: 999,
    code: 'EBADSIZE',
  })
  t.end()
})

t.test('error if non-string/buffer is written', t => {
  const mps = new MPS({size:1})
  mps.on('error', er => {
    t.match(er, {
      message: 'MinipassSized streams only work with string and buffer data'
    })
    t.end()
  })
  mps.write({some:'object'})
})

t.test('projectiles', t => {
  t.throws(() => new MPS(), {
    message: 'invalid expected size: undefined'
  }, 'size is required')
  t.throws(() => new MPS({size: true}), {
    message: 'invalid expected size: true'
  }, 'size must be number')
  t.throws(() => new MPS({size: NaN}), {
    message: 'invalid expected size: NaN'
  }, 'size must not be NaN')
  t.throws(() => new MPS({size:1.2}), {
    message: 'invalid expected size: 1.2'
  }, 'size must be integer')
  t.throws(() => new MPS({size: Infinity}), {
    message: 'invalid expected size: Infinity'
  }, 'size must be finite')
  t.throws(() => new MPS({size: -1}), {
    message: 'invalid expected size: -1'
  }, 'size must be positive')
  t.throws(() => new MPS({objectMode: true}), {
    message: 'MinipassSized streams only work with string and buffer data'
  }, 'no objectMode')
  t.throws(() => new MPS({size: Number.MAX_SAFE_INTEGER + 1000000}), {
    message: 'invalid expected size: 9007199255740992'
  })
  t.end()
})

t.test('exports SizeError class', t => {
  t.isa(MPS.SizeError, 'function')
  t.isa(MPS.SizeError.prototype, Error)
  t.end()
})