Best JavaScript code snippet using wpt
unrar.js
Source:unrar.js
...58 var headPos = bstream.bytePtr;59 // byte 1,260 info("Rar Volume Header @"+bstream.bytePtr);61 62 this.crc = bstream.readBits(16);63 info(" crc=" + this.crc);64 // byte 365 this.headType = bstream.readBits(8);66 info(" headType=" + this.headType);67 // Get flags68 // bytes 4,569 this.flags = {};70 this.flags.value = bstream.peekBits(16);71 72 info(" flags=" + twoByteValueToHexString(this.flags.value));73 switch (this.headType) {74 case MAIN_HEAD:75 this.flags.MHD_VOLUME = !!bstream.readBits(1);76 this.flags.MHD_COMMENT = !!bstream.readBits(1);77 this.flags.MHD_LOCK = !!bstream.readBits(1);78 this.flags.MHD_SOLID = !!bstream.readBits(1);79 this.flags.MHD_PACK_COMMENT = !!bstream.readBits(1);80 this.flags.MHD_NEWNUMBERING = this.flags.MHD_PACK_COMMENT;81 this.flags.MHD_AV = !!bstream.readBits(1);82 this.flags.MHD_PROTECT = !!bstream.readBits(1);83 this.flags.MHD_PASSWORD = !!bstream.readBits(1);84 this.flags.MHD_FIRSTVOLUME = !!bstream.readBits(1);85 this.flags.MHD_ENCRYPTVER = !!bstream.readBits(1);86 bstream.readBits(6); // unused87 break;88 case FILE_HEAD:89 this.flags.LHD_SPLIT_BEFORE = !!bstream.readBits(1); // 0x000190 this.flags.LHD_SPLIT_AFTER = !!bstream.readBits(1); // 0x000291 this.flags.LHD_PASSWORD = !!bstream.readBits(1); // 0x000492 this.flags.LHD_COMMENT = !!bstream.readBits(1); // 0x000893 this.flags.LHD_SOLID = !!bstream.readBits(1); // 0x001094 bstream.readBits(3); // unused95 this.flags.LHD_LARGE = !!bstream.readBits(1); // 0x010096 this.flags.LHD_UNICODE = !!bstream.readBits(1); // 0x020097 this.flags.LHD_SALT = !!bstream.readBits(1); // 0x040098 this.flags.LHD_VERSION = !!bstream.readBits(1); // 0x080099 this.flags.LHD_EXTTIME = !!bstream.readBits(1); // 0x1000100 this.flags.LHD_EXTFLAGS = !!bstream.readBits(1); // 0x2000101 bstream.readBits(2); // unused102 info(" LHD_SPLIT_BEFORE = " + this.flags.LHD_SPLIT_BEFORE);103 break;104 default:105 bstream.readBits(16);106 }107 108 // byte 6,7109 this.headSize = bstream.readBits(16);110 info(" headSize=" + this.headSize);111 switch (this.headType) {112 case MAIN_HEAD:113 this.highPosAv = bstream.readBits(16);114 this.posAv = bstream.readBits(32);115 if (this.flags.MHD_ENCRYPTVER) {116 this.encryptVer = bstream.readBits(8);117 }118 info("Found MAIN_HEAD with highPosAv=" + this.highPosAv + ", posAv=" + this.posAv);119 break;120 case FILE_HEAD:121 this.packSize = bstream.readBits(32);122 this.unpackedSize = bstream.readBits(32);123 this.hostOS = bstream.readBits(8);124 this.fileCRC = bstream.readBits(32);125 this.fileTime = bstream.readBits(32);126 this.unpVer = bstream.readBits(8);127 this.method = bstream.readBits(8);128 this.nameSize = bstream.readBits(16);129 this.fileAttr = bstream.readBits(32);130 131 if (this.flags.LHD_LARGE) {132 info("Warning: Reading in LHD_LARGE 64-bit size values");133 this.HighPackSize = bstream.readBits(32);134 this.HighUnpSize = bstream.readBits(32);135 } else {136 this.HighPackSize = 0;137 this.HighUnpSize = 0;138 if (this.unpackedSize == 0xffffffff) {139 this.HighUnpSize = 0x7fffffff140 this.unpackedSize = 0xffffffff;141 }142 }143 this.fullPackSize = 0;144 this.fullUnpackSize = 0;145 this.fullPackSize |= this.HighPackSize;146 this.fullPackSize <<= 32;147 this.fullPackSize |= this.packSize;148 149 // read in filename150 151 this.filename = bstream.readBytes(this.nameSize);152 for (var _i = 0, _s = ''; _i < this.filename.length; _i++) {153 _s += String.fromCharCode(this.filename[_i]);154 }155 156 this.filename = _s;157 158 if (this.flags.LHD_SALT) {159 info("Warning: Reading in 64-bit salt value");160 this.salt = bstream.readBits(64); // 8 bytes161 }162 163 if (this.flags.LHD_EXTTIME) {164 // 16-bit flags165 var extTimeFlags = bstream.readBits(16);166 167 // this is adapted straight out of arcread.cpp, Archive::ReadHeader()168 for (var I = 0; I < 4; ++I) {169 var rmode = extTimeFlags >> ((3-I)*4);170 if ((rmode & 8)==0)171 continue;172 if (I!=0)173 bstream.readBits(16);174 var count = (rmode&3);175 for (var J = 0; J < count; ++J) 176 bstream.readBits(8);177 }178 }179 180 if (this.flags.LHD_COMMENT) {181 info("Found a LHD_COMMENT");182 }183 184 185 while(headPos + this.headSize > bstream.bytePtr) bstream.readBits(1);186 187 info("Found FILE_HEAD with packSize=" + this.packSize + ", unpackedSize= " + this.unpackedSize + ", hostOS=" + this.hostOS + ", unpVer=" + this.unpVer + ", method=" + this.method + ", filename=" + this.filename);188 189 break;190 default:191 info("Found a header of type 0x" + byteValueToHexString(this.headType));192 // skip the rest of the header bytes (for now)193 bstream.readBytes( this.headSize - 7 );194 break;195 }196};197var BLOCK_LZ = 0,198 BLOCK_PPM = 1;199var rLDecode = [0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224],200 rLBits = [0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],201 rDBitLengthCounts = [4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,14,0,12],202 rSDDecode = [0,4,8,16,32,64,128,192],203 rSDBits = [2,2,3, 4, 5, 6, 6, 6];204 205var rDDecode = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32,206 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072,207 4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304,208 131072, 196608, 262144, 327680, 393216, 458752, 524288, 589824,209 655360, 720896, 786432, 851968, 917504, 983040];210var rDBits = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5,211 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14,212 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16];213var rLOW_DIST_REP_COUNT = 16;214var rNC = 299,215 rDC = 60,216 rLDC = 17,217 rRC = 28,218 rBC = 20,219 rHUFF_TABLE_SIZE = (rNC+rDC+rRC+rLDC);220var UnpBlockType = BLOCK_LZ;221var UnpOldTable = new Array(rHUFF_TABLE_SIZE);222var BD = { //bitdecode223 DecodeLen: new Array(16),224 DecodePos: new Array(16),225 DecodeNum: new Array(rBC)226};227var LD = { //litdecode228 DecodeLen: new Array(16),229 DecodePos: new Array(16),230 DecodeNum: new Array(rNC)231};232var DD = { //distdecode233 DecodeLen: new Array(16),234 DecodePos: new Array(16),235 DecodeNum: new Array(rDC)236};237var LDD = { //low dist decode238 DecodeLen: new Array(16),239 DecodePos: new Array(16),240 DecodeNum: new Array(rLDC)241};242var RD = { //rep decode243 DecodeLen: new Array(16),244 DecodePos: new Array(16),245 DecodeNum: new Array(rRC)246};247var rBuffer;248// read in Huffman tables for RAR249function RarReadTables(bstream) {250 var BitLength = new Array(rBC),251 Table = new Array(rHUFF_TABLE_SIZE);252 // before we start anything we need to get byte-aligned253 bstream.readBits( (8 - bstream.bitPtr) & 0x7 );254 255 if (bstream.readBits(1)) {256 info("Error! PPM not implemented yet");257 return;258 }259 260 if (!bstream.readBits(1)) { //discard old table261 for (var i = UnpOldTable.length; i--;) UnpOldTable[i] = 0;262 }263 // read in bit lengths264 for (var I = 0; I < rBC; ++I) {265 var Length = bstream.readBits(4);266 if (Length == 15) {267 var ZeroCount = bstream.readBits(4);268 if (ZeroCount == 0) {269 BitLength[I] = 15;270 }271 else {272 ZeroCount += 2;273 while (ZeroCount-- > 0 && I < rBC)274 BitLength[I++] = 0;275 --I;276 }277 }278 else {279 BitLength[I] = Length;280 }281 }282 283 // now all 20 bit lengths are obtained, we construct the Huffman Table:284 RarMakeDecodeTables(BitLength, 0, BD, rBC);285 286 var TableSize = rHUFF_TABLE_SIZE;287 //console.log(DecodeLen, DecodePos, DecodeNum);288 for (var i = 0; i < TableSize;) {289 var num = RarDecodeNumber(bstream, BD);290 if (num < 16) {291 Table[i] = (num + UnpOldTable[i]) & 0xf;292 i++;293 } else if(num < 18) {294 var N = (num == 16) ? (bstream.readBits(3) + 3) : (bstream.readBits(7) + 11);295 while (N-- > 0 && i < TableSize) {296 Table[i] = Table[i - 1];297 i++;298 }299 } else {300 var N = (num == 18) ? (bstream.readBits(3) + 3) : (bstream.readBits(7) + 11);301 while (N-- > 0 && i < TableSize) {302 Table[i++] = 0;303 }304 }305 }306 307 RarMakeDecodeTables(Table, 0, LD, rNC);308 RarMakeDecodeTables(Table, rNC, DD, rDC);309 RarMakeDecodeTables(Table, rNC + rDC, LDD, rLDC);310 RarMakeDecodeTables(Table, rNC + rDC + rLDC, RD, rRC); 311 312 for (var i = UnpOldTable.length; i--;) {313 UnpOldTable[i] = Table[i];314 }315 return true;316}317function RarDecodeNumber(bstream, dec) {318 var DecodeLen = dec.DecodeLen, DecodePos = dec.DecodePos, DecodeNum = dec.DecodeNum;319 var bitField = bstream.getBits() & 0xfffe;320 //some sort of rolled out binary search321 var bits = ((bitField < DecodeLen[8])?322 ((bitField < DecodeLen[4])?323 ((bitField < DecodeLen[2])?324 ((bitField < DecodeLen[1])?1:2)325 :((bitField < DecodeLen[3])?3:4))326 :(bitField < DecodeLen[6])?327 ((bitField < DecodeLen[5])?5:6)328 :((bitField < DecodeLen[7])?7:8))329 :((bitField < DecodeLen[12])?330 ((bitField < DecodeLen[10])?331 ((bitField < DecodeLen[9])?9:10)332 :((bitField < DecodeLen[11])?11:12))333 :(bitField < DecodeLen[14])?334 ((bitField < DecodeLen[13])?13:14)335 :15));336 bstream.readBits(bits);337 var N = DecodePos[bits] + ((bitField - DecodeLen[bits -1]) >>> (16 - bits));338 339 return DecodeNum[N];340}341function RarMakeDecodeTables(BitLength, offset, dec, size) {342 var DecodeLen = dec.DecodeLen, DecodePos = dec.DecodePos, DecodeNum = dec.DecodeNum;343 var LenCount = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],344 TmpPos = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],345 N = 0, M = 0;346 for (var i = DecodeNum.length; i--;) DecodeNum[i] = 0;347 for (var i = 0; i < size; i++) {348 LenCount[BitLength[i + offset] & 0xF]++;349 }350 LenCount[0] = 0;351 TmpPos[0] = 0;352 DecodePos[0] = 0;353 DecodeLen[0] = 0;354 355 for (var I = 1; I < 16; ++I) {356 N = 2 * (N+LenCount[I]);357 M = (N << (15-I));358 if (M > 0xFFFF)359 M = 0xFFFF;360 DecodeLen[I] = M;361 DecodePos[I] = DecodePos[I-1] + LenCount[I-1];362 TmpPos[I] = DecodePos[I];363 }364 for (I = 0; I < size; ++I)365 if (BitLength[I + offset] != 0)366 DecodeNum[ TmpPos[ BitLength[offset + I] & 0xF ]++] = I;367}368// TODO: implement369function Unpack15(bstream, Solid) {370 info("ERROR! RAR 1.5 compression not supported");371}372function Unpack20(bstream, Solid) {373 var destUnpSize = rBuffer.data.length;374 var oldDistPtr = 0;375 376 RarReadTables20(bstream);377 while (destUnpSize > rBuffer.ptr) {378 var num = RarDecodeNumber(bstream, LD);379 if (num < 256) {380 rBuffer.insertByte(num);381 continue;382 }383 if (num > 269) {384 var Length = rLDecode[num -= 270] + 3;385 if ((Bits = rLBits[num]) > 0) {386 Length += bstream.readBits(Bits);387 }388 var DistNumber = RarDecodeNumber(bstream, DD);389 var Distance = rDDecode[DistNumber] + 1;390 if ((Bits = rDBits[DistNumber]) > 0) {391 Distance += bstream.readBits(Bits);392 }393 if (Distance >= 0x2000) {394 Length++;395 if(Distance >= 0x40000) Length++;396 }397 lastLength = Length;398 lastDist = rOldDist[oldDistPtr++ & 3] = Distance;399 RarCopyString(Length, Distance);400 continue;401 }402 if (num == 269) {403 RarReadTables20(bstream);404 RarUpdateProgress()405 406 continue;407 }408 if (num == 256) {409 lastDist = rOldDist[oldDistPtr++ & 3] = lastDist;410 RarCopyString(lastLength, lastDist);411 continue;412 }413 if (num < 261) {414 var Distance = rOldDist[(oldDistPtr - (num - 256)) & 3];415 var LengthNumber = RarDecodeNumber(bstream, RD);416 var Length = rLDecode[LengthNumber] +2;417 if ((Bits = rLBits[LengthNumber]) > 0) {418 Length += bstream.readBits(Bits);419 }420 if (Distance >= 0x101) {421 Length++;422 if (Distance >= 0x2000) {423 Length++424 if (Distance >= 0x40000) Length++;425 }426 }427 lastLength = Length;428 lastDist = rOldDist[oldDistPtr++ & 3] = Distance;429 RarCopyString(Length, Distance);430 continue;431 }432 if (num < 270) {433 var Distance = rSDDecode[num -= 261] + 1;434 if ((Bits = rSDBits[num]) > 0) {435 Distance += bstream.readBits(Bits);436 }437 lastLength = 2;438 lastDist = rOldDist[oldDistPtr++ & 3] = Distance;439 RarCopyString(2, Distance);440 continue;441 }442 443 }444 RarUpdateProgress()445}446function RarUpdateProgress() {447 var change = rBuffer.ptr - currentBytesUnarchivedInFile;448 currentBytesUnarchivedInFile = rBuffer.ptr;449 currentBytesUnarchived += change;450 postProgress();451}452var rNC20 = 298,453 rDC20 = 48,454 rRC20 = 28,455 rBC20 = 19,456 rMC20 = 257;457var UnpOldTable20 = new Array(rMC20 * 4);458function RarReadTables20(bstream) {459 var BitLength = new Array(rBC20);460 var Table = new Array(rMC20 * 4);461 var TableSize, N, I;462 var AudioBlock = bstream.readBits(1);463 if (!bstream.readBits(1))464 for (var i = UnpOldTable20.length; i--;) UnpOldTable20[i] = 0;465 TableSize = rNC20 + rDC20 + rRC20;466 for (var I = 0; I < rBC20; I++)467 BitLength[I] = bstream.readBits(4);468 RarMakeDecodeTables(BitLength, 0, BD, rBC20);469 I = 0;470 while (I < TableSize) {471 var num = RarDecodeNumber(bstream, BD);472 if (num < 16) {473 Table[I] = num + UnpOldTable20[I] & 0xf;474 I++;475 } else if(num == 16) {476 N = bstream.readBits(2) + 3;477 while (N-- > 0 && I < TableSize) {478 Table[I] = Table[I - 1];479 I++;480 }481 } else {482 if (num == 17) {483 N = bstream.readBits(3) + 3;484 } else {485 N = bstream.readBits(7) + 11;486 }487 while (N-- > 0 && I < TableSize) {488 Table[I++] = 0;489 }490 }491 }492 RarMakeDecodeTables(Table, 0, LD, rNC20);493 RarMakeDecodeTables(Table, rNC20, DD, rDC20);494 RarMakeDecodeTables(Table, rNC20 + rDC20, RD, rRC20);495 for (var i = UnpOldTable20.length; i--;) UnpOldTable20[i] = Table[i];496}497var lowDistRepCount = 0, prevLowDist = 0;498var rOldDist = [0,0,0,0];499var lastDist;500var lastLength;501function Unpack29(bstream, Solid) {502 // lazy initialize rDDecode and rDBits503 var DDecode = new Array(rDC);504 var DBits = new Array(rDC);505 506 var Dist=0,BitLength=0,Slot=0;507 508 for (var I = 0; I < rDBitLengthCounts.length; I++,BitLength++) {509 for (var J = 0; J < rDBitLengthCounts[I]; J++,Slot++,Dist+=(1<<BitLength)) {510 DDecode[Slot]=Dist;511 DBits[Slot]=BitLength;512 }513 }514 515 var Bits;516 //tablesRead = false;517 rOldDist = [0,0,0,0]518 519 lastDist = 0;520 lastLength = 0;521 for (var i = UnpOldTable.length; i--;) UnpOldTable[i] = 0;522 523 // read in Huffman tables524 RarReadTables(bstream);525 526 while (true) {527 var num = RarDecodeNumber(bstream, LD);528 529 if (num < 256) {530 rBuffer.insertByte(num);531 continue;532 }533 if (num >= 271) {534 var Length = rLDecode[num -= 271] + 3;535 if ((Bits = rLBits[num]) > 0) {536 Length += bstream.readBits(Bits);537 }538 var DistNumber = RarDecodeNumber(bstream, DD);539 var Distance = DDecode[DistNumber]+1;540 if ((Bits = DBits[DistNumber]) > 0) {541 if (DistNumber > 9) {542 if (Bits > 4) {543 Distance += ((bstream.getBits() >>> (20 - Bits)) << 4);544 bstream.readBits(Bits - 4);545 //todo: check this546 }547 if (lowDistRepCount > 0) {548 lowDistRepCount--;549 Distance += prevLowDist;550 } else {551 var LowDist = RarDecodeNumber(bstream, LDD);552 if (LowDist == 16) {553 lowDistRepCount = rLOW_DIST_REP_COUNT - 1;554 Distance += prevLowDist;555 } else {556 Distance += LowDist;557 prevLowDist = LowDist;558 }559 }560 } else {561 Distance += bstream.readBits(Bits);562 }563 }564 if (Distance >= 0x2000) {565 Length++;566 if (Distance >= 0x40000) {567 Length++;568 }569 }570 RarInsertOldDist(Distance);571 RarInsertLastMatch(Length, Distance);572 RarCopyString(Length, Distance);573 continue;574 }575 if (num == 256) {576 if (!RarReadEndOfBlock(bstream)) break;577 578 continue;579 }580 if (num == 257) {581 //console.log("READVMCODE");582 if (!RarReadVMCode(bstream)) break;583 continue;584 }585 if (num == 258) {586 if (lastLength != 0) {587 RarCopyString(lastLength, lastDist);588 }589 continue;590 }591 if (num < 263) {592 var DistNum = num - 259;593 var Distance = rOldDist[DistNum];594 for (var I = DistNum; I > 0; I--) {595 rOldDist[I] = rOldDist[I-1];596 }597 rOldDist[0] = Distance;598 var LengthNumber = RarDecodeNumber(bstream, RD);599 var Length = rLDecode[LengthNumber] + 2;600 if ((Bits = rLBits[LengthNumber]) > 0) {601 Length += bstream.readBits(Bits);602 }603 RarInsertLastMatch(Length, Distance);604 RarCopyString(Length, Distance);605 continue;606 }607 if (num < 272) {608 var Distance = rSDDecode[num -= 263] + 1;609 if ((Bits = rSDBits[num]) > 0) {610 Distance += bstream.readBits(Bits);611 }612 RarInsertOldDist(Distance);613 RarInsertLastMatch(2, Distance);614 RarCopyString(2, Distance);615 continue;616 }617 618 }619 RarUpdateProgress()620}621function RarReadEndOfBlock(bstream) {622 623 RarUpdateProgress()624 var NewTable = false, NewFile = false;625 if (bstream.readBits(1)) {626 NewTable = true;627 } else {628 NewFile = true;629 NewTable = !!bstream.readBits(1);630 }631 //tablesRead = !NewTable;632 return !(NewFile || NewTable && !RarReadTables(bstream));633}634function RarReadVMCode(bstream) {635 var FirstByte = bstream.readBits(8);636 var Length = (FirstByte & 7) + 1;637 if (Length == 7) {638 Length = bstream.readBits(8) + 7;639 } else if(Length == 8) {640 Length = bstream.readBits(16);641 }642 var vmCode = [];643 for(var I = 0; I < Length; I++) {644 //do something here with cheking readbuf645 vmCode.push(bstream.readBits(8));646 }647 return RarAddVMCode(FirstByte, vmCode, Length);648}649function RarAddVMCode(firstByte, vmCode, length) {650 //console.log(vmCode);651 if (vmCode.length > 0) {652 info("Error! RarVM not supported yet!");653 }654 return true;655}656function RarInsertLastMatch(length, distance) {657 lastDist = distance;658 lastLength = length;659}...
inflater.js
Source:inflater.js
1function inflate(data, config={}) {2 let {approx,progress,notrim}=config;3 let report=Date.now();4 if (!approx)5 approx = data.length;6 let readpos = 0;7 let result = new Uint8Array(approx);8 let writepos = 0;9 let last;10 do {11 if(progress && Date.now()-report>100){12 progress(readpos,data.length*8);13 report=Date.now();14 }15 last = readbit();16 let typ = readbits(2);17// console.log(last, typ);18 let litlenhuff, disthuff;19 switch (typ) {20 case 1:21 throw "no 1 yet";22 case 0:23 skipfrac();24 let len = readbits(16);25// console.log(len);26 if ((len ^ readbits(16)) !== 65535)27 throw "Type0 len-nlen mismatch";28 while (len--)29// result.push(readbits(8));//!!30 write(readbits(8));31 //result[writepos++] = readbits(8);//!!32 break;33 case 3:34 throw "Type3?";35 case 2:36 let numlitlens = readbits(5) + 257;37 let numdists = readbits(5) + 1;38 let numlencodes = readbits(4) + 4;39// console.log(numlitlens + "-" + numdists + "-" + numlencodes);40 let lens = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];41 let lenlens = new Array(19).fill(0);42 for (let i = 0; i < numlencodes; i++)43 lenlens[lens[i]] = readbits(3);44 let lenrake = rake(8);45 for (let i = 0; i < lenlens.length; i++)46 lenrake[lenlens[i]].push(i);47 let lenhuff = huff(lenrake);48 {49 let litlenrake = rake(16);50 let distrake = rake(16);51 let currrake = litlenrake;52 let curr = 0;53 let reps = 0;54 let i = 0;55 let cnt = 0;56 while (cnt < numlitlens + numdists) {57 if (reps <= 0) {58 let code = readcode(lenhuff);59 if (code < 16) {60 curr = code;61 reps = 1;62 } else if (code === 16)63 reps = readbits(2) + 3;64 else if (code === 17) {65 curr = 0;66 reps = readbits(3) + 3;67 } else if (code === 18) {68 curr = 0;69 reps = readbits(7) + 11;70 } else71 throw new Exception(code + ">18");72 }73 reps--;74 currrake[curr].push(i++);75 cnt++;76 if (cnt === numlitlens) {77 currrake = distrake;78 i = 0;79 }80 }81 litlenhuff = huff(litlenrake);82 disthuff = huff(distrake);83 }84 while (true) {85 let code = readcode(litlenhuff);86 if (code === 256)87 break;88 if (code < 256) {89 //result.push(code);90 //result[writepos++] = code;91 write(code);92// console.log(String.fromCharCode(code));93 } else {94 let len;95 if (code < 265)96 len = code - 254;97 else if (code === 285)98 len = 258;99 else {100 code -= 261;101 let bits = code >> 2;/// 4;102 let mod = code & 3;//% 4;103 len = (mod + 4) * (1 << bits) + 3 + readbits(bits);104 }105// console.log("Len:" + len);106// let dist = disthuff==null?107// (Integer.reverse(readbits(5)) >>> 27):readcode(disthuff);108 let dist = readcode(disthuff);109 if (dist >= 4) {110 dist -= 2;111 let bits = dist >> 1;/// 2;112 let mod = dist & 1;//% 2;113 dist = (mod + 2) * (1 << bits) + readbits(bits);114 }115 dist++;116 while (len-- > 0) {117 write(result[writepos - dist]);118 }119 }120 }121 }122 } while (!last);123 console.log(readpos, data.length * 8);124 console.log(writepos);125 if(!notrim)126 resize(writepos);127 return notrim?{result,length:writepos}:result;128 function readbit() {129 return (data[readpos >> 3] >> (readpos++ & 7) & 1);130 }131 function readbits(n) {132 let ret = 0, shift = 0;133 while (n-- > 0)134 ret += readbit() << shift++;135 return ret;136 }137 function skipfrac() {138 while (readpos & 7)139 readpos++;140 }141 function readcode(huff) {142 let code = 1;143 do {144 code = (code << 1) + readbit();145 if (code >= (1 << 20))146 throw "stream desync";147 } while (typeof huff[code] === "undefined");148 code = huff[code];149 return code;150 }151 function rake(n) {152 let ret = [];153 while (n-- > 0)154 ret.push([]);155 return ret;156 }157 function huff(rake) {158 rake[0] = [];159 let base = 0;160 let ret = [];161 for (let bits = 1; bits < rake.length; bits++) {162 base = (base + rake[bits - 1].length) << 1;163 let code = base + (1 << bits);164 for (let sym of rake[bits])165 ret[code++] = sym;166 }167 return ret;168 }169 function write(b) {170 if (writepos >= result.length)171 resize(result.length * 2);172 result[writepos++] = b;173 }174 function resize(len) {175 if(result.length===len)176 return;177 let realloc=new Uint8Array(len);178 if(len>result.length)179 for(let i=0;i<result.length;i++)180 realloc[i]=result[i];181 else182 for(let i=0;i<len;i++)183 realloc[i]=result[i];184 result = realloc;185 }...
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var fs = require('fs');3var file = fs.readFileSync('test.bin');4var buffer = new Buffer(file);5var result = wptoolkit.readBits(buffer, 0, 8);6var result = wptoolkit.readBits(buffer, 8, 8);7var result = wptoolkit.readBits(buffer, 16, 8);8var result = wptoolkit.readBits(buffer, 24, 8);9var result = wptoolkit.readBits(buffer, 32, 8);10var result = wptoolkit.readBits(buffer, 40, 8);11var result = wptoolkit.readBits(buffer, 48, 8);12var result = wptoolkit.readBits(buffer, 56, 8);13var result = wptoolkit.readBits(buffer, 64, 8);14var result = wptoolkit.readBits(buffer, 72, 8);15var result = wptoolkit.readBits(buffer, 80, 8);16var result = wptoolkit.readBits(buffer, 88, 8);17var result = wptoolkit.readBits(buffer, 96, 8);18var result = wptoolkit.readBits(buffer, 104, 8);19var result = wptoolkit.readBits(buffer, 112, 8);20var result = wptoolkit.readBits(buffer, 120, 8);21var result = wptoolkit.readBits(buffer, 128, 8);22var result = wptoolkit.readBits(buffer, 136, 8);
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools('Wikipedia');3wp.readBits(function(err, bits) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(bits);8 }9});10{ 'wikibase-shortdesc': 'Wikipedia is a free online encyclopedia, created and edited by volunteers around the world and hosted by the Wikimedia Foundation.',11 'wikibase-sitelinks': 'enwiki:Wikipedia; commonswiki:Wikipedia; dewiki:Wikipedia; eswiki:Wikipedia; frwiki:Wikipedia; itwiki:Wikipedia; nlwiki:Wikipedia; plwiki:Wikipedia; ruwiki:Wikipedia; svwiki:Wikipedia; viwiki:Wikipedia; zhwiki:Wikipedia; arwiki:ويكيبيديا; bgwiki:Уикипедия; cawiki:Viquipèdia; cswiki:Wikipedie; cywiki:Wicipedia; elwiki:Βικιπαίδεια; enwiki:Wikipedia; eowiki:Vikipedio; eswiki:Wikipedia; etwiki:Vikipeedia; euwiki:Wikipedia; fawiki:ویکیپدیا; fiwiki:Wikipedia; frwiki:Wikipedia; glwiki:Viquipedia; hewiki:ויקיפדיה; hrwiki:Wikipedija; huwiki:Wikipédia; idwiki:Wikipedia; itwiki:Wikipedia; jawiki:ウィキペディア; kowiki:위키백과; kshwiki:Wikipedia; lawiki:Vicipaedia; lvwiki:Vikipēdija; nlwiki:Wikipedia; plwiki:Wikipedia; ptwiki:Wikipédia; ruwiki:Википедия; skwiki:Wikipédia; slwiki:Wikipedija; svwiki:Wikipedia; trwiki:Vikipedi; ukwiki:Вікіпедія; viwiki:Wikipedia; warwiki:Wikipedia; zh-yuewiki:
Using AI Code Generation
1var wptools = require('wptools');2var wp = wptools.page('Albert Einstein');3wp.get(function(err, page) {4 console.log(page.readBits());5});6var wptools = require('wptools');7var wp = wptools.page('Albert Einstein');8wp.get(function(err, page) {9 console.log(page.readBits('infobox'));10});11var wptools = require('wptools');12var wp = wptools.page('Albert Einstein');13wp.get(function(err, page) {14 console.log(page.readBits('infobox', 'birth_date'));15});16var wptools = require('wptools');17var wp = wptools.page('Albert Einstein');18wp.get(function(err, page) {19 console.log(page.readBits('infobox', 'birth_date', 'birth_place'));20});21var wptools = require('wptools');22var wp = wptools.page('Albert Einstein');23wp.get(function(err, page) {24 console.log(page.readBits('infobox', 'birth_date', 'birth_place', 'image'));25});26var wptools = require('wptools');27var wp = wptools.page('Albert Einstein');28wp.get(function(err, page) {29 console.log(page.readBits('infobox', 'birth_date', 'birth_place', 'image', 'birth_name'));30});31var wptools = require('wptools');32var wp = wptools.page('Albert Einstein');33wp.get(function(err, page) {34 console.log(page.readBits('infobox', 'birth_date', 'birth_place', 'image', 'birth_name', 'death_date'));35});36var wptools = require('wptools');37var wp = wptools.page('Albert Einstein');
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var data = fs.readFileSync('test.jpg');4var buf = new Buffer(data);5var wpt = new wptools(buf);6var bits = wpt.readBits(0, 64);7console.log(bits);
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools();3var page = wp.page('Barack Obama');4page.readBits(function(err, bits){5 console.log(bits);6});7var wptools = require('wptools');8var wp = new wptools();9var page = wp.page('Barack Obama');10page.readBits(function(err, bits){11 console.log(bits);12});13var wptools = require('wptools');14var wp = new wptools();15var page = wp.page('Barack Obama');16page.readBits(function(err, bits){17 console.log(bits);18});19var wptools = require('wptools');20var wp = new wptools();21var page = wp.page('Barack Obama');22page.readBits(function(err, bits){23 console.log(bits);24});25var wptools = require('wptools');26var wp = new wptools();27var page = wp.page('Barack Obama');28page.readBits(function(err, bits){29 console.log(bits);30});31var wptools = require('wptools');32var wp = new wptools();33var page = wp.page('Barack Obama');34page.readBits(function(err, bits){35 console.log(bits);36});37var wptools = require('wptools');38var wp = new wptools();39var page = wp.page('Barack Obama');40page.readBits(function(err, bits){41 console.log(bits);42});43var wptools = require('wptools');44var wp = new wptools();45var page = wp.page('Barack Obama');46page.readBits(function(err, bits){47 console.log(bits);48});49var wptools = require('wpt
Using AI Code Generation
1var fs = require('fs');2var wptoolkit = require('wptoolkit');3var wp = require('wptoolkit/lib/wptoolkit').wp;4var file = fs.readFileSync('test.wp');5var test = wptoolkit.readBits(file, 0, 32);6console.log('test', test);7var fs = require('fs');8var wptoolkit = require('wptoolkit');9var wp = require('wptoolkit/lib/wptoolkit').wp;10var file = fs.readFileSync('test.wp');11var test = wptoolkit.readBits(file, 0, 32);12console.log('test', test);13var wptoolkit = require('wptoolkit');14var wp = require('wptoolkit/lib/wptoolkit').wp;15var test = wp.readBits(file, 0, 32);16var wptoolkit = require('wptoolkit');17var wp = require('wptoolkit/lib/wptoolkit').wp;18var test = wptoolkit.readBits(file, 0, 32);19var wptoolkit = require('wptoolkit');20var wp = require('wptoolkit/lib/wptoolkit').wp;21var test = wp.readBits(file, 0, 32);22var wptoolkit = require('wptoolkit');23var wp = require('wptoolkit/lib/wptoolkit').wp;24var test = wptoolkit.readBits(file, 0, 32);25var wptoolkit = require('wptoolkit');26var wp = require('wptoolkit/lib/wptoolkit
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!