How to use RunLengthStream method in wpt

Best JavaScript code snippet using wpt

run_length_stream.js

Source:run_length_stream.js Github

copy

Full Screen

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}...

Full Screen

Full Screen

RunLengthStream.ts

Source:RunLengthStream.ts Github

copy

Full Screen

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}...

Full Screen

Full Screen

RunLengthStream.spec.ts

Source:RunLengthStream.spec.ts Github

copy

Full Screen

...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 });...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful