react / wstein / node_modules / browserify / node_modules / browserify-zlib / test / test-zlib-invalid-input.js
80529 views// Copyright Joyent, Inc. and other Node contributors.1//2// Permission is hereby granted, free of charge, to any person obtaining a3// copy of this software and associated documentation files (the4// "Software"), to deal in the Software without restriction, including5// without limitation the rights to use, copy, modify, merge, publish,6// distribute, sublicense, and/or sell copies of the Software, and to permit7// persons to whom the Software is furnished to do so, subject to the8// following conditions:9//10// The above copyright notice and this permission notice shall be included11// in all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS14// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF15// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN16// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,17// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19// USE OR OTHER DEALINGS IN THE SOFTWARE.2021// test uncompressing invalid input2223var tape = require('tape'),24zlib = require('../');2526tape('non-strings', function(t) {27var nonStringInputs = [1, true, {a: 1}, ['a']];28t.plan(12);2930nonStringInputs.forEach(function(input) {31// zlib.gunzip should not throw an error when called with bad input.32t.doesNotThrow(function() {33zlib.gunzip(input, function(err, buffer) {34// zlib.gunzip should pass the error to the callback.35t.ok(err);36});37});38});39});4041tape('unzips', function(t) {42// zlib.Unzip classes need to get valid data, or else they'll throw.43var unzips = [ zlib.Unzip(),44zlib.Gunzip(),45zlib.Inflate(),46zlib.InflateRaw() ];4748t.plan(4);49unzips.forEach(function (uz, i) {50uz.on('error', function(er) {51t.ok(er);52});5354uz.on('end', function(er) {55throw new Error('end event should not be emitted '+uz.constructor.name);56});5758// this will trigger error event59uz.write('this is not valid compressed data.');60});61});626364