README.md (3622B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # isgzipBuffer 22 23 > Test if a value is a [gzip][gzip-rfc-1952] buffer. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isgzipBuffer = require( '@stdlib/assert/is-gzip-buffer' ); 31 ``` 32 33 #### isgzipBuffer( value ) 34 35 Tests if a value is a [`gzip`][gzip-rfc-1952] buffer. 36 37 ```javascript 38 var Uint8Array = require( '@stdlib/array/uint8' ); 39 40 var buf = new Uint8Array( 20 ); 41 buf[ 0 ] = 31; // 0x1f => magic number 42 buf[ 1 ] = 139; // 0x8b 43 buf[ 2 ] = 8; // 0x08 => compression method 44 45 var bool = isgzipBuffer( buf ); 46 // returns true 47 48 bool = isgzipBuffer( [] ); 49 // returns false 50 ``` 51 52 </section> 53 54 <!-- /.usage --> 55 56 <section class="notes"> 57 58 ## Notes 59 60 - A [gzip][gzip-rfc-1952] buffer is defined as either a Node.js [`Buffer`][@stdlib/buffer/ctor] or [`Uint8Array`][@stdlib/array/uint8] which contains a 10-byte header, a body containing the compressed payload, and an 8-byte footer containing a CRC-32 checksum and the length of the original uncompressed data, modulo `2^32`. 61 - This function only examines the 10-byte header to ensure the header includes the expected magic number and compression method. The function does not perform an integrity check. 62 63 </section> 64 65 <!-- /.notes --> 66 67 <section class="examples"> 68 69 ## Examples 70 71 <!-- eslint no-undef: "error" --> 72 73 ```javascript 74 var Float32Array = require( '@stdlib/array/float32' ); 75 var Float64Array = require( '@stdlib/array/float64' ); 76 var Int8Array = require( '@stdlib/array/int8' ); 77 var Int16Array = require( '@stdlib/array/int16' ); 78 var Int32Array = require( '@stdlib/array/int32' ); 79 var Uint8Array = require( '@stdlib/array/uint8' ); 80 var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); 81 var Uint16Array = require( '@stdlib/array/uint16' ); 82 var Uint32Array = require( '@stdlib/array/uint32' ); 83 var isgzipBuffer = require( '@stdlib/assert/is-gzip-buffer' ); 84 85 var buf = new Uint8Array( 20 ); 86 buf[ 0 ] = 31; // 0x1f => magic number 87 buf[ 1 ] = 139; // 0x8b 88 buf[ 2 ] = 8; // 0x08 => compression method 89 90 var bool = isgzipBuffer( buf ); 91 // returns true 92 93 bool = isgzipBuffer( new Float32Array( 20 ) ); 94 // returns false 95 96 bool = isgzipBuffer( new Int8Array( 20 ) ); 97 // returns false 98 99 bool = isgzipBuffer( new Uint8Array( 20 ) ); 100 // returns false 101 102 bool = isgzipBuffer( new Uint8ClampedArray( 20 ) ); 103 // returns false 104 105 bool = isgzipBuffer( new Int16Array( 20 ) ); 106 // returns false 107 108 bool = isgzipBuffer( new Uint16Array( 20 ) ); 109 // returns false 110 111 bool = isgzipBuffer( new Int32Array( 20 ) ); 112 // returns false 113 114 bool = isgzipBuffer( new Uint32Array( 20 ) ); 115 // returns false 116 117 bool = isgzipBuffer( new Float64Array( 20 ) ); 118 // returns false 119 120 bool = isgzipBuffer( new Array( 20 ) ); 121 // returns false 122 123 bool = isgzipBuffer( {} ); 124 // returns false 125 126 bool = isgzipBuffer( null ); 127 // returns false 128 ``` 129 130 </section> 131 132 <!-- /.examples --> 133 134 <section class="links"> 135 136 [gzip-rfc-1952]: https://tools.ietf.org/html/rfc1952 137 138 [@stdlib/buffer/ctor]: https://www.npmjs.com/package/@stdlib/buffer-ctor 139 140 [@stdlib/array/uint8]: https://www.npmjs.com/package/@stdlib/array-uint8 141 142 </section> 143 144 <!-- /.links -->