react / wstein / node_modules / browserify / node_modules / browserify-zlib / test / test-zlib-from-string.js
80534 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 compressing and uncompressing a string with zlib2223var tape = require('tape');24var zlib = require('../');2526var inputString = '\u03A9\u03A9Lorem ipsum dolor sit amet, consectetur adipiscing el' +27'it. Morbi faucibus, purus at gravida dictum, libero arcu convallis la' +28'cus, in commodo libero metus eu nisi. Nullam commodo, neque nec porta' +29' placerat, nisi est fermentum augue, vitae gravida tellus sapien sit ' +30'amet tellus. Aenean non diam orci. Proin quis elit turpis. Suspendiss' +31'e non diam ipsum. Suspendisse nec ullamcorper odio. Vestibulum arcu m' +32'i, sodales non suscipit id, ultrices ut massa. Sed ac sem sit amet ar' +33'cu malesuada fermentum. Nunc sed. ';34var expectedBase64Deflate = 'eJxdUUtOQzEMvMoc4OndgT0gJCT2buJWlpI4jePeqZfpm' +35'XAKLRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkDlKWLJWkncJG5403HQXAkT3' +36'Jw29B9uIEmToMukglZ0vS6ociBh4JG8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491Lofo' +37'AbWh8do43oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+RSQsGoC7dn2t/xjhduTA1N' +38'WyQIZR0pbHwMDatnD+crPqKSqGPHp1vnlsWM/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqq' +39'qfKBtNMhe3OZh6N95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOHaFE4RdpnGavKtrB5xzfO/Ll9';40var expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN' +41'496pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajNPk6QOUpYslaSdwkbnjT' +42'cdBcCRPcnDb0H24gSZOgy6SCVnS9LqhyIGHgkbyxXihUsRQKK0raTGrVbM+cKEcPOxoYr' +43'Lj3Uuh+gBtaHx2jjeh65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCwagLt2fa3/G' +44'OF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+eWxYz/Tu5t/tuF4XuSpKPzgGbRHV9h' +45'N9ory+qqp8oG00yF7c5mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2s' +46'HnHNzRtagj5AQAA';4748tape('deflate', function(t) {49t.plan(1);50zlib.deflate(inputString, function(err, buffer) {51t.equal(buffer.toString('base64'), expectedBase64Deflate,52'deflate encoded string should match');53});54});5556tape('gzip', function(t) {57t.plan(1);58zlib.gzip(inputString, function(err, buffer) {59// Can't actually guarantee that we'll get exactly the same60// deflated bytes when we compress a string, since the header61// depends on stuff other than the input string itself.62// However, decrypting it should definitely yield the same63// result that we're expecting, and this should match what we get64// from inflating the known valid deflate data.65zlib.gunzip(buffer, function(err, gunzipped) {66t.equal(gunzipped.toString(), inputString,67'Should get original string after gzip/gunzip');68});69});70});7172tape('unzip deflate', function(t) {73t.plan(1);74var buffer = new Buffer(expectedBase64Deflate, 'base64');75zlib.unzip(buffer, function(err, buffer) {76t.equal(buffer.toString(), inputString,77'decoded inflated string should match');78});79});8081tape('unzip gzip', function(t) {82t.plan(1);83buffer = new Buffer(expectedBase64Gzip, 'base64');84zlib.unzip(buffer, function(err, buffer) {85t.equal(buffer.toString(), inputString,86'decoded gunzipped string should match');87});88});899091