@@ -3,42 +3,44 @@ import crc32 from "crc-32";
33import { BinaryStream , DeadEndStream } from "./helpers/index.js" ;
44import CRC32Stream from "../lib/crc32-stream.js" ;
55/*global before,describe,it */
6- describe ( 'CRC32Stream' , function ( ) {
7- it ( 'should checksum data while passing through data' , function ( done ) {
8- const binary = new BinaryStream ( 1024 * 16 ) ;
9- const checksum = new CRC32Stream ( ) ;
10- const deadend = new DeadEndStream ( ) ;
11- checksum . on ( 'end' , function ( ) {
12- assert . equal ( checksum . digest ( ) . readUInt32BE ( 0 ) , 3893830384 ) ;
13- assert . equal ( checksum . digest ( 'hex' ) , 'e81722f0' ) ;
14- assert . equal ( checksum . hex ( ) , 'E81722F0' ) ;
15- assert . equal ( checksum . size ( ) , 16384 ) ;
16- done ( ) ;
17- } ) ;
18- checksum . pipe ( deadend ) ;
19- binary . pipe ( checksum ) ;
6+
7+ describe ( "CRC32Stream" , function ( ) {
8+ it ( "should checksum data while passing through data" , function ( done ) {
9+ const binary = new BinaryStream ( 1024 * 16 ) ;
10+ const checksum = new CRC32Stream ( ) ;
11+ const deadend = new DeadEndStream ( ) ;
12+ checksum . on ( "end" , function ( ) {
13+ assert . equal ( checksum . digest ( ) . readUInt32BE ( 0 ) , 3893830384 ) ;
14+ assert . equal ( checksum . digest ( "hex" ) , "e81722f0" ) ;
15+ assert . equal ( checksum . hex ( ) , "E81722F0" ) ;
16+ assert . equal ( checksum . size ( ) , 16384 ) ;
17+ done ( ) ;
2018 } ) ;
21- it ( 'should have same checksum when bytes written together or separately' , function ( done ) {
22- const checksum = new CRC32Stream ( ) ;
23- const deadend = new DeadEndStream ( ) ;
24- const expectedChecksumValue = crc32 . buf ( [ 157 , 10 , 217 , 109 , 100 , 200 , 300 ] ) >>> 0 ;
25- checksum . on ( 'end' , function ( ) {
26- assert . equal ( checksum . digest ( ) . readUInt32BE ( 0 ) , expectedChecksumValue ) ;
27- done ( ) ;
28- } ) ;
29- checksum . write ( Buffer . from ( [ 157 , 10 , 217 , 109 ] ) ) ;
30- checksum . write ( Buffer . from ( [ 100 , 200 , 300 ] ) ) ;
31- checksum . end ( ) ;
32- checksum . pipe ( deadend ) ;
19+ checksum . pipe ( deadend ) ;
20+ binary . pipe ( checksum ) ;
21+ } ) ;
22+ it ( "should have same checksum when bytes written together or separately" , function ( done ) {
23+ const checksum = new CRC32Stream ( ) ;
24+ const deadend = new DeadEndStream ( ) ;
25+ const expectedChecksumValue =
26+ crc32 . buf ( [ 157 , 10 , 217 , 109 , 100 , 200 , 300 ] ) >>> 0 ;
27+ checksum . on ( "end" , function ( ) {
28+ assert . equal ( checksum . digest ( ) . readUInt32BE ( 0 ) , expectedChecksumValue ) ;
29+ done ( ) ;
3330 } ) ;
34- it ( 'should gracefully handle having no data chunks passed to it' , function ( done ) {
35- const checksum = new CRC32Stream ( ) ;
36- const deadend = new DeadEndStream ( ) ;
37- checksum . on ( 'end' , function ( ) {
38- assert . equal ( checksum . digest ( ) . readUInt32BE ( 0 ) , 0 ) ;
39- done ( ) ;
40- } ) ;
41- checksum . pipe ( deadend ) ;
42- checksum . end ( ) ;
31+ checksum . write ( Buffer . from ( [ 157 , 10 , 217 , 109 ] ) ) ;
32+ checksum . write ( Buffer . from ( [ 100 , 200 , 300 ] ) ) ;
33+ checksum . end ( ) ;
34+ checksum . pipe ( deadend ) ;
35+ } ) ;
36+ it ( "should gracefully handle having no data chunks passed to it" , function ( done ) {
37+ const checksum = new CRC32Stream ( ) ;
38+ const deadend = new DeadEndStream ( ) ;
39+ checksum . on ( "end" , function ( ) {
40+ assert . equal ( checksum . digest ( ) . readUInt32BE ( 0 ) , 0 ) ;
41+ done ( ) ;
4342 } ) ;
43+ checksum . pipe ( deadend ) ;
44+ checksum . end ( ) ;
45+ } ) ;
4446} ) ;
0 commit comments