Best JavaScript code snippet using wpt
run_length_stream.js
Source: run_length_stream.js
1/**2 * @licstart The following is the entire license notice for the3 * Javascript code in this page4 *5 * Copyright 2021 Mozilla Foundation6 *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 at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * 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 and17 * limitations under the License.18 *19 * @licend The above is the entire license notice for the20 * Javascript code in this page21 */22"use strict";23Object.defineProperty(exports, "__esModule", {24 value: true25});26exports.RunLengthStream = void 0;27var _decode_stream = require("./decode_stream.js");28class RunLengthStream extends _decode_stream.DecodeStream {29 constructor(str, maybeLength) {30 super(maybeLength);31 this.str = str;32 this.dict = str.dict;33 }34 readBlock() {35 const repeatHeader = this.str.getBytes(2);36 if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {37 this.eof = true;38 return;39 }40 let buffer;41 let bufferLength = this.bufferLength;42 let n = repeatHeader[0];43 if (n < 128) {44 buffer = this.ensureBuffer(bufferLength + n + 1);45 buffer[bufferLength++] = repeatHeader[1];46 if (n > 0) {47 const source = this.str.getBytes(n);48 buffer.set(source, bufferLength);49 bufferLength += n;50 }51 } else {52 n = 257 - n;53 const b = repeatHeader[1];54 buffer = this.ensureBuffer(bufferLength + n + 1);55 for (let i = 0; i < n; i++) {56 buffer[bufferLength++] = b;57 }58 }59 this.bufferLength = bufferLength;60 }61}...
RunLengthStream.ts
Source: RunLengthStream.ts
1/*2 * Copyright 2012 Mozilla Foundation3 *4 * The RunLengthStream class contained in this file is a TypeScript port of the5 * JavaScript RunLengthStream class in Mozilla's pdf.js project, made available6 * under the Apache 2.0 open source license.7 */8import DecodeStream from 'src/core/streams/DecodeStream';9import { StreamType } from 'src/core/streams/Stream';10class RunLengthStream extends DecodeStream {11 private stream: StreamType;12 constructor(stream: StreamType, maybeLength?: number) {13 super(maybeLength);14 this.stream = stream;15 }16 protected readBlock() {17 // The repeatHeader has following format. The first byte defines type of run18 // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes19 // (in addition to the second byte from the header), n = 129 through 255 -20 // duplicate the second byte from the header (257 - n) times, n = 128 - end.21 const repeatHeader = this.stream.getBytes(2);22 if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {23 this.eof = true;24 return;25 }26 let buffer;27 let bufferLength = this.bufferLength;28 let n = repeatHeader[0];29 if (n < 128) {30 // copy n bytes31 buffer = this.ensureBuffer(bufferLength + n + 1);32 buffer[bufferLength++] = repeatHeader[1];33 if (n > 0) {34 const source = this.stream.getBytes(n);35 buffer.set(source, bufferLength);36 bufferLength += n;37 }38 } else {39 n = 257 - n;40 const b = repeatHeader[1];41 buffer = this.ensureBuffer(bufferLength + n + 1);42 for (let i = 0; i < n; i++) {43 buffer[bufferLength++] = b;44 }45 }46 this.bufferLength = bufferLength;47 }48}...
RunLengthStream.spec.ts
Source: RunLengthStream.spec.ts
...7 FILES.forEach((file) => {8 it(`can decode run length encoded data (${file})`, () => {9 const encoded = new Uint8Array(fs.readFileSync(`${DIR}/${file}.encoded`));10 const decoded = new Uint8Array(fs.readFileSync(`${DIR}/${file}.decoded`));11 const stream = new RunLengthStream(new Stream(encoded));12 expect(stream.decode()).toEqual(decoded);13 });14 });...
Check out the latest blogs from LambdaTest on this topic:
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
We launched LT Browser in 2020, and we were overwhelmed by the response as it was awarded as the #5 product of the day on the ProductHunt platform. Today, after 74,585 downloads and 7,000 total test runs with an average of 100 test runs each day, the LT Browser has continued to help developers build responsive web designs in a jiffy.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.
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!!