How to use byteString method in wpt

Best JavaScript code snippet using wpt

bytestring_test.js

Source:bytestring_test.js Github

copy

Full Screen

1goog.module('proto.im.integration.ByteStringFieldsTest');2goog.setTestOnly();3const ByteString = goog.require('protobuf.ByteString');4const {arrayBufferSlice} = goog.require('protobuf.binary.typedArrays');5const /** !ArrayBuffer */ TEST_BYTES = new Uint8Array([1, 2, 3, 4]).buffer;6const /** !ByteString */ TEST_STRING = ByteString.fromArrayBuffer(TEST_BYTES);7const /** !ArrayBuffer */ PREFIXED_TEST_BYTES =8 new Uint8Array([0, 1, 2, 3, 4]).buffer;9const /** string */ HALLO_IN_BASE64 = 'aGFsbG8=';10const /** string */ HALLO_IN_BASE64_WITH_SPACES = 'a G F s b G 8=';11const /** !ArrayBufferView */ BYTES_WITH_HALLO = new Uint8Array([12 'h'.charCodeAt(0),13 'a'.charCodeAt(0),14 'l'.charCodeAt(0),15 'l'.charCodeAt(0),16 'o'.charCodeAt(0),17]);18describe('ByteString does', () => {19 it('create bytestring from buffer', () => {20 const byteString =21 ByteString.fromArrayBuffer(arrayBufferSlice(TEST_BYTES, 0));22 expect(byteString.toArrayBuffer()).toEqual(TEST_BYTES);23 expect(byteString.toUint8ArrayUnsafe()).toEqual(new Uint8Array(TEST_BYTES));24 });25 it('create bytestring from ArrayBufferView', () => {26 const byteString =27 ByteString.fromArrayBufferView(new Uint8Array(TEST_BYTES));28 expect(byteString.toArrayBuffer()).toEqual(TEST_BYTES);29 expect(byteString.toUint8ArrayUnsafe()).toEqual(new Uint8Array(TEST_BYTES));30 });31 it('create bytestring from subarray', () => {32 const byteString = ByteString.fromArrayBufferView(33 new Uint8Array(TEST_BYTES, /* offset */ 1, /* length */ 2));34 const expected = new Uint8Array([2, 3]);35 expect(new Uint8Array(byteString.toArrayBuffer())).toEqual(expected);36 expect(byteString.toUint8ArrayUnsafe()).toEqual(expected);37 });38 it('create bytestring from Uint8Array (unsafe)', () => {39 const array = new Uint8Array(TEST_BYTES);40 const byteString = ByteString.fromUint8ArrayUnsafe(array);41 expect(byteString.toArrayBuffer()).toEqual(array.buffer);42 expect(byteString.toUint8ArrayUnsafe()).toBe(array);43 });44 it('create bytestring from base64 string', () => {45 const byteString = ByteString.fromBase64String(HALLO_IN_BASE64);46 expect(byteString.toBase64String()).toEqual(HALLO_IN_BASE64);47 expect(byteString.toArrayBuffer()).toEqual(BYTES_WITH_HALLO.buffer);48 expect(byteString.toUint8ArrayUnsafe()).toEqual(BYTES_WITH_HALLO);49 });50 it('preserve immutability if underlying buffer changes: from buffer', () => {51 const buffer = new ArrayBuffer(4);52 const array = new Uint8Array(buffer);53 array[0] = 1;54 array[1] = 2;55 array[2] = 3;56 array[3] = 4;57 const byteString = ByteString.fromArrayBuffer(buffer);58 const otherBuffer = byteString.toArrayBuffer();59 expect(otherBuffer).not.toBe(buffer);60 expect(new Uint8Array(otherBuffer)).toEqual(array);61 // modify the original buffer62 array[0] = 5;63 // Are we still returning the original bytes?64 expect(new Uint8Array(byteString.toArrayBuffer())).toEqual(new Uint8Array([65 1, 2, 3, 466 ]));67 });68 it('preserve immutability if underlying buffer changes: from ArrayBufferView',69 () => {70 const buffer = new ArrayBuffer(4);71 const array = new Uint8Array(buffer);72 array[0] = 1;73 array[1] = 2;74 array[2] = 3;75 array[3] = 4;76 const byteString = ByteString.fromArrayBufferView(array);77 const otherBuffer = byteString.toArrayBuffer();78 expect(otherBuffer).not.toBe(buffer);79 expect(new Uint8Array(otherBuffer)).toEqual(array);80 // modify the original buffer81 array[0] = 5;82 // Are we still returning the original bytes?83 expect(new Uint8Array(byteString.toArrayBuffer()))84 .toEqual(new Uint8Array([1, 2, 3, 4]));85 });86 it('mutate if underlying buffer changes: from Uint8Array (unsafe)', () => {87 const buffer = new ArrayBuffer(4);88 const array = new Uint8Array(buffer);89 array[0] = 1;90 array[1] = 2;91 array[2] = 3;92 array[3] = 4;93 const byteString = ByteString.fromUint8ArrayUnsafe(array);94 const otherBuffer = byteString.toArrayBuffer();95 expect(otherBuffer).not.toBe(buffer);96 expect(new Uint8Array(otherBuffer)).toEqual(array);97 // modify the original buffer98 array[0] = 5;99 // We are no longer returning the original bytes100 expect(new Uint8Array(byteString.toArrayBuffer())).toEqual(new Uint8Array([101 5, 2, 3, 4102 ]));103 });104 it('preserve immutability for returned buffers: toArrayBuffer', () => {105 const byteString = ByteString.fromArrayBufferView(new Uint8Array(4));106 const buffer1 = byteString.toArrayBuffer();107 const buffer2 = byteString.toArrayBuffer();108 expect(buffer1).toEqual(buffer2);109 const array1 = new Uint8Array(buffer1);110 array1[0] = 1;111 expect(buffer1).not.toEqual(buffer2);112 });113 it('does not preserve immutability for returned buffers: toUint8ArrayUnsafe',114 () => {115 const byteString = ByteString.fromUint8ArrayUnsafe(new Uint8Array(4));116 const array1 = byteString.toUint8ArrayUnsafe();117 const array2 = byteString.toUint8ArrayUnsafe();118 expect(array1).toEqual(array2);119 array1[0] = 1;120 expect(array1).toEqual(array2);121 });122 it('throws when created with null ArrayBufferView', () => {123 expect(124 () => ByteString.fromArrayBufferView(125 /** @type {!ArrayBufferView} */ (/** @type{*} */ (null))))126 .toThrow();127 });128 it('throws when created with null buffer', () => {129 expect(130 () => ByteString.fromBase64String(131 /** @type {string} */ (/** @type{*} */ (null))))132 .toThrow();133 });134 it('convert base64 to ArrayBuffer', () => {135 const other = ByteString.fromBase64String(HALLO_IN_BASE64);136 expect(BYTES_WITH_HALLO).toEqual(new Uint8Array(other.toArrayBuffer()));137 });138 it('convert base64 with spaces to ArrayBuffer', () => {139 const other = ByteString.fromBase64String(HALLO_IN_BASE64_WITH_SPACES);140 expect(new Uint8Array(other.toArrayBuffer())).toEqual(BYTES_WITH_HALLO);141 });142 it('convert bytes to base64', () => {143 const other = ByteString.fromArrayBufferView(BYTES_WITH_HALLO);144 expect(HALLO_IN_BASE64).toEqual(other.toBase64String());145 });146 it('equal empty bytetring', () => {147 const empty = ByteString.fromArrayBuffer(new ArrayBuffer(0));148 expect(ByteString.EMPTY.equals(empty)).toEqual(true);149 });150 it('equal empty bytestring constructed from ArrayBufferView', () => {151 const empty = ByteString.fromArrayBufferView(new Uint8Array(0));152 expect(ByteString.EMPTY.equals(empty)).toEqual(true);153 });154 it('equal empty bytestring constructed from Uint8Array (unsafe)', () => {155 const empty = ByteString.fromUint8ArrayUnsafe(new Uint8Array(0));156 expect(ByteString.EMPTY.equals(empty)).toEqual(true);157 });158 it('equal empty bytestring constructed from base64', () => {159 const empty = ByteString.fromBase64String('');160 expect(ByteString.EMPTY.equals(empty)).toEqual(true);161 });162 it('equal other instance', () => {163 const other = ByteString.fromArrayBuffer(arrayBufferSlice(TEST_BYTES, 0));164 expect(TEST_STRING.equals(other)).toEqual(true);165 });166 it('not equal different instance', () => {167 const other =168 ByteString.fromArrayBuffer(new Uint8Array([1, 2, 3, 4, 5]).buffer);169 expect(TEST_STRING.equals(other)).toEqual(false);170 });171 it('equal other instance constructed from ArrayBufferView', () => {172 const other =173 ByteString.fromArrayBufferView(new Uint8Array(PREFIXED_TEST_BYTES, 1));174 expect(TEST_STRING.equals(other)).toEqual(true);175 });176 it('not equal different instance constructed from ArrayBufferView', () => {177 const other =178 ByteString.fromArrayBufferView(new Uint8Array([1, 2, 3, 4, 5]));179 expect(TEST_STRING.equals(other)).toEqual(false);180 });181 it('equal other instance constructed from Uint8Array (unsafe)', () => {182 const other =183 ByteString.fromUint8ArrayUnsafe(new Uint8Array(PREFIXED_TEST_BYTES, 1));184 expect(TEST_STRING.equals(other)).toEqual(true);185 });186 it('not equal different instance constructed from Uint8Array (unsafe)',187 () => {188 const other =189 ByteString.fromUint8ArrayUnsafe(new Uint8Array([1, 2, 3, 4, 5]));190 expect(TEST_STRING.equals(other)).toEqual(false);191 });192 it('have same hashcode for empty bytes', () => {193 const empty = ByteString.fromArrayBuffer(new ArrayBuffer(0));194 expect(ByteString.EMPTY.hashCode()).toEqual(empty.hashCode());195 });196 it('have same hashcode for test bytes', () => {197 const other = ByteString.fromArrayBuffer(arrayBufferSlice(TEST_BYTES, 0));198 expect(TEST_STRING.hashCode()).toEqual(other.hashCode());199 });200 it('have same hashcode for test bytes', () => {201 const other = ByteString.fromArrayBufferView(202 new Uint8Array(arrayBufferSlice(TEST_BYTES, 0)));203 expect(TEST_STRING.hashCode()).toEqual(other.hashCode());204 });205 it('have same hashcode for different instance constructed with base64',206 () => {207 const other = ByteString.fromBase64String(HALLO_IN_BASE64);208 expect(ByteString.fromArrayBufferView(BYTES_WITH_HALLO).hashCode())209 .toEqual(other.hashCode());210 });211 it('preserves the length of a Uint8Array', () => {212 const original = new Uint8Array([105, 183, 51, 251, 253, 118, 247]);213 const afterByteString = new Uint8Array(214 ByteString.fromArrayBufferView(original).toArrayBuffer());215 expect(afterByteString).toEqual(original);216 });217 it('preserves the length of a base64 value', () => {218 const expected = new Uint8Array([105, 183, 51, 251, 253, 118, 247]);219 const afterByteString = new Uint8Array(220 ByteString.fromBase64String('abcz+/129w').toArrayBuffer());221 expect(afterByteString).toEqual(expected);222 });223 it('preserves the length of a base64 value with padding', () => {224 const expected = new Uint8Array([105, 183, 51, 251, 253, 118, 247]);225 const afterByteString = new Uint8Array(226 ByteString.fromBase64String('abcz+/129w==').toArrayBuffer());227 expect(afterByteString).toEqual(expected);228 });...

Full Screen

Full Screen

bytestring.js

Source:bytestring.js Github

copy

Full Screen

1/**2 * @fileoverview Provides ByteString as a basic data type for protos.3 */4goog.module('protobuf.ByteString');5const base64 = goog.require('goog.crypt.base64');6const {arrayBufferSlice, cloneArrayBufferView, hashUint8Array, uint8ArrayEqual} = goog.require('protobuf.binary.typedArrays');7/**8 * Immutable sequence of bytes.9 *10 * Bytes can be obtained as an ArrayBuffer or a base64 encoded string.11 * @final12 */13class ByteString {14 /**15 * @param {?Uint8Array} bytes16 * @param {?string} base6417 * @private18 */19 constructor(bytes, base64) {20 /** @private {?Uint8Array}*/21 this.bytes_ = bytes;22 /** @private {?string} */23 this.base64_ = base64;24 /** @private {number} */25 this.hashCode_ = 0;26 }27 /**28 * Constructs a ByteString instance from a base64 string.29 * @param {string} value30 * @return {!ByteString}31 */32 static fromBase64String(value) {33 if (value == null) {34 throw new Error('value must not be null');35 }36 return new ByteString(/* bytes */ null, value);37 }38 /**39 * Constructs a ByteString from an array buffer.40 * @param {!ArrayBuffer} bytes41 * @param {number=} start42 * @param {number=} end43 * @return {!ByteString}44 */45 static fromArrayBuffer(bytes, start = 0, end = undefined) {46 return new ByteString(47 new Uint8Array(arrayBufferSlice(bytes, start, end)), /* base64 */ null);48 }49 /**50 * Constructs a ByteString from any ArrayBufferView (e.g. DataView,51 * TypedArray, Uint8Array, etc.).52 * @param {!ArrayBufferView} bytes53 * @return {!ByteString}54 */55 static fromArrayBufferView(bytes) {56 return new ByteString(cloneArrayBufferView(bytes), /* base64 */ null);57 }58 /**59 * Constructs a ByteString from an Uint8Array. DON'T MODIFY the underlying60 * ArrayBuffer, since the ByteString directly uses it without making a copy.61 *62 * This method exists so that internal APIs can construct a ByteString without63 * paying the penalty of copying an ArrayBuffer when that ArrayBuffer is not64 * supposed to change. It is exposed to a limited number of internal classes65 * through bytestring_internal.js.66 *67 * @param {!Uint8Array} bytes68 * @return {!ByteString}69 * @package70 */71 static fromUint8ArrayUnsafe(bytes) {72 return new ByteString(bytes, /* base64 */ null);73 }74 /**75 * Returns this ByteString as an ArrayBuffer.76 * @return {!ArrayBuffer}77 */78 toArrayBuffer() {79 const bytes = this.ensureBytes_();80 return arrayBufferSlice(81 bytes.buffer, bytes.byteOffset, bytes.byteOffset + bytes.byteLength);82 }83 /**84 * Returns this ByteString as an Uint8Array. DON'T MODIFY the returned array,85 * since the ByteString holds the reference to the same array.86 *87 * This method exists so that internal APIs can get contents of a ByteString88 * without paying the penalty of copying an ArrayBuffer. It is exposed to a89 * limited number of internal classes through bytestring_internal.js.90 * @return {!Uint8Array}91 * @package92 */93 toUint8ArrayUnsafe() {94 return this.ensureBytes_();95 }96 /**97 * Returns this ByteString as a base64 encoded string.98 * @return {string}99 */100 toBase64String() {101 return this.ensureBase64String_();102 }103 /**104 * Returns true for Bytestrings that contain identical values.105 * @param {*} other106 * @return {boolean}107 */108 equals(other) {109 if (this === other) {110 return true;111 }112 if (!(other instanceof ByteString)) {113 return false;114 }115 const otherByteString = /** @type {!ByteString} */ (other);116 return uint8ArrayEqual(this.ensureBytes_(), otherByteString.ensureBytes_());117 }118 /**119 * Returns a number (int32) that is suitable for using in hashed structures.120 * @return {number}121 */122 hashCode() {123 if (this.hashCode_ == 0) {124 this.hashCode_ = hashUint8Array(this.ensureBytes_());125 }126 return this.hashCode_;127 }128 /**129 * Returns true if the bytestring is empty.130 * @return {boolean}131 */132 isEmpty() {133 if (this.bytes_ != null && this.bytes_.byteLength == 0) {134 return true;135 }136 if (this.base64_ != null && this.base64_.length == 0) {137 return true;138 }139 return false;140 }141 /**142 * @return {!Uint8Array}143 * @private144 */145 ensureBytes_() {146 if (this.bytes_) {147 return this.bytes_;148 }149 return this.bytes_ = base64.decodeStringToUint8Array(150 /** @type {string} */ (this.base64_));151 }152 /**153 * @return {string}154 * @private155 */156 ensureBase64String_() {157 if (this.base64_ == null) {158 this.base64_ = base64.encodeByteArray(this.bytes_);159 }160 return this.base64_;161 }162}163/** @const {!ByteString} */164ByteString.EMPTY = new ByteString(new Uint8Array(0), null);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var myWpt = new wpt('www.webpagetest.org');3 if (err) {4 console.log(err);5 }6 else {7 myWpt.getTestResults(data.data.testId, function(err, data) {8 if (err) {9 console.log(err);10 }11 else {12 console.log(data);13 }14 });15 }16});17{statusCode: 200,18 {statusCode: 200,19 {testId: '141115_VZ_6b3f6e3f3e9e2f2f7d0c1b1a1a1b',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');3}, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6 wpt.getByteString(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');13}, function(err, data) {14 if (err) return console.error(err);15 console.log(data);16 wpt.getByteString(data.data.testId, function(err, data) {17 if (err) return console.error(err);18 console.log(data);19 });20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');23}, function(err, data) {24 if (err) return console.error(err);25 console.log(data);26 wpt.getByteString(data.data.testId, function(err, data) {27 if (err) return console.error(err);28 console.log(data);29 });30});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', options.key);5var testOptions = {6};7wpt.runTest(testURL, testOptions, function(err, data) {8 if (err) return console.error(err);9 console.log('Test status:', data.statusCode);10 console.log('Test ID:', data.data.testId);11 console.log('Test URL:', data.data.summary);12 console.log('Test results:', data.data.jsonUrl);13 console.log('Test results:', data.data.userUrl);14 console.log('Test results:', data.data.xmlUrl);15 console.log('Test results:', data.data.csvUrl);16 console.log('Test results:', data.data.harUrl);17 console.log('Test results:', data.data.pagespeedUrl);18 console.log('Test results:', data.data.videoUrl);19 console.log('Test results:', data.data.runs);20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = new wptools('Albert Einstein');3wp.get(function(err, data) {4 console.log(data);5});6var wptools = require('wptools');7var wp = new wptools('Albert Einstein');8wp.get(function(err, data) {9 console.log(data);10});11var wptools = require('wptools');12var wp = new wptools('Albert Einstein');13wp.get(function(err, data) {14 console.log(data);15});16var wptools = require('wptools');17var wp = new wptools('Albert Einstein');18wp.get(function(err, data) {19 console.log(data);20});21var wptools = require('wptools');22var wp = new wptools('Albert Einstein');23wp.get(function(err, data) {24 console.log(data);25});26var wptools = require('wptools');27var wp = new wptools('Albert Einstein');28wp.get(function(err, data) {29 console.log(data);30});31var wptools = require('wptools');32var wp = new wptools('Albert Einstein');33wp.get(function(err, data) {34 console.log(data);35});36var wptools = require('wptools');37var wp = new wptools('Albert Einstein');38wp.get(function(err, data) {39 console.log(data);40});41var wptools = require('wptools');42var wp = new wptools('Albert Einstein');43wp.get(function(err, data) {44 console.log(data);45});46var wptools = require('wptools');47var wp = new wptools('Albert Einstein');48wp.get(function(err, data) {49 console.log(data);50});51var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = wptools.page('Albert Einstein');3wp.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var wp = wptools.page('Albert Einstein');8wp.get(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var wp = wptools.page('Albert Einstein');13wp.get(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var wp = wptools.page('Albert Einstein');18wp.get(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var wp = wptools.page('Albert Einstein');23wp.get(function(err, resp) {24 console.log(resp);25});26var wptools = require('wptools');27var wp = wptools.page('Albert Einstein');28wp.get(function(err, resp) {29 console.log(resp);30});31var wptools = require('wptools');32var wp = wptools.page('Albert Einstein');33wp.get(function(err, resp) {34 console.log(resp);35});36var wptools = require('wptools');37var wp = wptools.page('Albert Einstein');38wp.get(function(err, resp) {39 console.log(resp);40});41var wptools = require('wptools');42var wp = wptools.page('Albert Einstein');43wp.get(function(err, resp) {44 console.log(resp);45});46var wptools = require('wptools');47var wp = wptools.page('Albert Einstein');48wp.get(function(err, resp) {49 console.log(resp);50});51var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var str = "This is a string";2str = str.replace(/'/g, "\'");3var str = "This is a string";4str = str.replace(/'/g, "\'");5var str = "This is a string";6str = str.replace(/'/g, "\'");7var str = "This is a string";8str = str.replace(/'/g, "\'");9var str = "This is a string";10str = str.replace(/'/g, "\'");11var str = "This is a string";12str = str.replace(/'/g, "\'");13var str = "This is a string";14str = str.replace(/'/g, "\'");15var str = "This is a string";16str = str.replace(/'/g, "\'");17var str = "This is a string";18str = str.replace(/'/g, "\'");19var str = "This is a string";20str = str.replace(/'/g, "\'");21var str = "This is a string";22str = str.replace(/'/g, "\'");23var str = "This is a string";24str = str.replace(/'/g, "\'");25var str = "This is a string";26str = str.replace(/'/g, "\'");27var str = "This is a string";28str = str.replace(/'/g, "\'");29var str = "This is a string";30str = str.replace(/'/g, "\'

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = new wptools('wikipedia', 'en', 'CERN');3wp.get(function(err, data) {4 console.log(data);5});6var wptools = require('wptools');7var wp = new wptools('wikipedia', 'en', 'CERN');8wp.get(function(err, data) {9 console.log(data);10});11var wptools = require('wptools');12var wp = new wptools('wikipedia', 'en', 'CERN');13wp.get(function(err, data) {14 console.log(data);15});16var wptools = require('wptools');17var wp = new wptools('wikipedia', 'en', 'CERN');18wp.get(function(err, data) {19 console.log(data);20});21var wptools = require('wptools');22var wp = new wptools('wikipedia', 'en', 'CERN');23wp.get(function(err, data) {24 console.log(data);25});26var wptools = require('wptools');27var wp = new wptools('wikipedia', 'en', 'CERN');28wp.get(function(err, data) {29 console.log(data);30});31var wptools = require('wptools');32var wp = new wptools('wikipedia', 'en', 'CERN');33wp.get(function(err, data) {34 console.log(data);35});36var wptools = require('wptools');37var wp = new wptools('wikipedia', 'en', 'CERN');38wp.get(function(err, data) {39 console.log(data);40});41var wptools = require('wpt

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