11cb0ef41Sopenharmony_ci// Copyright Joyent, Inc. and other Node contributors.
21cb0ef41Sopenharmony_ci//
31cb0ef41Sopenharmony_ci// Permission is hereby granted, free of charge, to any person obtaining a
41cb0ef41Sopenharmony_ci// copy of this software and associated documentation files (the
51cb0ef41Sopenharmony_ci// "Software"), to deal in the Software without restriction, including
61cb0ef41Sopenharmony_ci// without limitation the rights to use, copy, modify, merge, publish,
71cb0ef41Sopenharmony_ci// distribute, sublicense, and/or sell copies of the Software, and to permit
81cb0ef41Sopenharmony_ci// persons to whom the Software is furnished to do so, subject to the
91cb0ef41Sopenharmony_ci// following conditions:
101cb0ef41Sopenharmony_ci//
111cb0ef41Sopenharmony_ci// The above copyright notice and this permission notice shall be included
121cb0ef41Sopenharmony_ci// in all copies or substantial portions of the Software.
131cb0ef41Sopenharmony_ci//
141cb0ef41Sopenharmony_ci// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
151cb0ef41Sopenharmony_ci// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
161cb0ef41Sopenharmony_ci// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
171cb0ef41Sopenharmony_ci// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
181cb0ef41Sopenharmony_ci// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
191cb0ef41Sopenharmony_ci// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
201cb0ef41Sopenharmony_ci// USE OR OTHER DEALINGS IN THE SOFTWARE.
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci'use strict';
231cb0ef41Sopenharmony_ci// Test compressing and uncompressing a string with zlib
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciconst common = require('../common');
261cb0ef41Sopenharmony_ciconst assert = require('assert');
271cb0ef41Sopenharmony_ciconst zlib = require('zlib');
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciconst inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing eli' +
301cb0ef41Sopenharmony_ci                    't. Morbi faucibus, purus at gravida dictum, libero arcu ' +
311cb0ef41Sopenharmony_ci                    'convallis lacus, in commodo libero metus eu nisi. Nullam' +
321cb0ef41Sopenharmony_ci                    ' commodo, neque nec porta placerat, nisi est fermentum a' +
331cb0ef41Sopenharmony_ci                    'ugue, vitae gravida tellus sapien sit amet tellus. Aenea' +
341cb0ef41Sopenharmony_ci                    'n non diam orci. Proin quis elit turpis. Suspendisse non' +
351cb0ef41Sopenharmony_ci                    ' diam ipsum. Suspendisse nec ullamcorper odio. Vestibulu' +
361cb0ef41Sopenharmony_ci                    'm arcu mi, sodales non suscipit id, ultrices ut massa. S' +
371cb0ef41Sopenharmony_ci                    'ed ac sem sit amet arcu malesuada fermentum. Nunc sed. ';
381cb0ef41Sopenharmony_ciconst expectedBase64Deflate = 'eJxdUUtOQzEMvMoc4OndgT0gJCT2buJWlpI4jePeqZfpmX' +
391cb0ef41Sopenharmony_ci                              'AKLRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkD' +
401cb0ef41Sopenharmony_ci                              'lKWLJWkncJG5403HQXAkT3Jw29B9uIEmToMukglZ0vS6oc' +
411cb0ef41Sopenharmony_ci                              'iBh4JG8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491LofoA' +
421cb0ef41Sopenharmony_ci                              'bWh8do43oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+' +
431cb0ef41Sopenharmony_ci                              'RSQsGoC7dn2t/xjhduTA1NWyQIZR0pbHwMDatnD+crPqKS' +
441cb0ef41Sopenharmony_ci                              'qGPHp1vnlsWM/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqqq' +
451cb0ef41Sopenharmony_ci                              'fKBtNMhe3OZh6N95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOH' +
461cb0ef41Sopenharmony_ci                              'aFE4RdpnGavKtrB5xzfO/Ll9';
471cb0ef41Sopenharmony_ciconst expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN4' +
481cb0ef41Sopenharmony_ci                           '96pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajN' +
491cb0ef41Sopenharmony_ci                           'Pk6QOUpYslaSdwkbnjTcdBcCRPcnDb0H24gSZOgy6SCVnS9Lq' +
501cb0ef41Sopenharmony_ci                           'hyIGHgkbyxXihUsRQKK0raTGrVbM+cKEcPOxoYrLj3Uuh+gBt' +
511cb0ef41Sopenharmony_ci                           'aHx2jjeh65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCw' +
521cb0ef41Sopenharmony_ci                           'agLt2fa3/GOF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+' +
531cb0ef41Sopenharmony_ci                           'eWxYz/Tu5t/tuF4XuSpKPzgGbRHV9hN9ory+qqp8oG00yF7c5' +
541cb0ef41Sopenharmony_ci                           'mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2' +
551cb0ef41Sopenharmony_ci                           'sHnHNzRtagj5AQAA';
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_cizlib.deflate(inputString, common.mustCall((err, buffer) => {
581cb0ef41Sopenharmony_ci  zlib.inflate(buffer, common.mustCall((err, inflated) => {
591cb0ef41Sopenharmony_ci    assert.strictEqual(inflated.toString(), inputString);
601cb0ef41Sopenharmony_ci  }));
611cb0ef41Sopenharmony_ci}));
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_cizlib.gzip(inputString, common.mustCall((err, buffer) => {
641cb0ef41Sopenharmony_ci  // Can't actually guarantee that we'll get exactly the same
651cb0ef41Sopenharmony_ci  // deflated bytes when we compress a string, since the header
661cb0ef41Sopenharmony_ci  // depends on stuff other than the input string itself.
671cb0ef41Sopenharmony_ci  // However, decrypting it should definitely yield the same
681cb0ef41Sopenharmony_ci  // result that we're expecting, and this should match what we get
691cb0ef41Sopenharmony_ci  // from inflating the known valid deflate data.
701cb0ef41Sopenharmony_ci  zlib.gunzip(buffer, common.mustCall((err, gunzipped) => {
711cb0ef41Sopenharmony_ci    assert.strictEqual(gunzipped.toString(), inputString);
721cb0ef41Sopenharmony_ci  }));
731cb0ef41Sopenharmony_ci}));
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_cilet buffer = Buffer.from(expectedBase64Deflate, 'base64');
761cb0ef41Sopenharmony_cizlib.unzip(buffer, common.mustCall((err, buffer) => {
771cb0ef41Sopenharmony_ci  assert.strictEqual(buffer.toString(), inputString);
781cb0ef41Sopenharmony_ci}));
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_cibuffer = Buffer.from(expectedBase64Gzip, 'base64');
811cb0ef41Sopenharmony_cizlib.unzip(buffer, common.mustCall((err, buffer) => {
821cb0ef41Sopenharmony_ci  assert.strictEqual(buffer.toString(), inputString);
831cb0ef41Sopenharmony_ci}));
84