Best JavaScript code snippet using wpt
midifile.js
Source:midifile.js
...17 18 function readEvent(stream) {19 var event = {};20 event.deltaTime = stream.readVarInt();21 var eventTypeByte = stream.readInt8();22 if ((eventTypeByte & 0xf0) == 0xf0) {23 /* system / meta event */24 if (eventTypeByte == 0xff) {25 /* meta event */26 event.type = 'meta';27 var subtypeByte = stream.readInt8();28 var length = stream.readVarInt();29 switch(subtypeByte) {30 case 0x00:31 event.subtype = 'sequenceNumber';32 if (length != 2) throw "Expected length for sequenceNumber event is 2, got " + length;33 event.number = stream.readInt16();34 return event;35 case 0x01:36 event.subtype = 'text';37 event.text = stream.read(length);38 return event;39 case 0x02:40 event.subtype = 'copyrightNotice';41 event.text = stream.read(length);42 return event;43 case 0x03:44 event.subtype = 'trackName';45 event.text = stream.read(length);46 return event;47 case 0x04:48 event.subtype = 'instrumentName';49 event.text = stream.read(length);50 return event;51 case 0x05:52 event.subtype = 'lyrics';53 event.text = stream.read(length);54 return event;55 case 0x06:56 event.subtype = 'marker';57 event.text = stream.read(length);58 return event;59 case 0x07:60 event.subtype = 'cuePoint';61 event.text = stream.read(length);62 return event;63 case 0x20:64 event.subtype = 'midiChannelPrefix';65 if (length != 1) throw "Expected length for midiChannelPrefix event is 1, got " + length;66 event.channel = stream.readInt8();67 return event;68 case 0x2f:69 event.subtype = 'endOfTrack';70 if (length != 0) throw "Expected length for endOfTrack event is 0, got " + length;71 return event;72 case 0x51:73 event.subtype = 'setTempo';74 if (length != 3) throw "Expected length for setTempo event is 3, got " + length;75 event.microsecondsPerBeat = (76 (stream.readInt8() << 16)77 + (stream.readInt8() << 8)78 + stream.readInt8()79 )80 return event;81 case 0x54:82 event.subtype = 'smpteOffset';83 if (length != 5) throw "Expected length for smpteOffset event is 5, got " + length;84 var hourByte = stream.readInt8();85 event.frameRate = {86 0x00: 24, 0x20: 25, 0x40: 29, 0x60: 3087 }[hourByte & 0x60];88 event.hour = hourByte & 0x1f;89 event.min = stream.readInt8();90 event.sec = stream.readInt8();91 event.frame = stream.readInt8();92 event.subframe = stream.readInt8();93 return event;94 case 0x58:95 event.subtype = 'timeSignature';96 if (length != 4) throw "Expected length for timeSignature event is 4, got " + length;97 event.numerator = stream.readInt8();98 event.denominator = Math.pow(2, stream.readInt8());99 event.metronome = stream.readInt8();100 event.thirtyseconds = stream.readInt8();101 return event;102 case 0x59:103 event.subtype = 'keySignature';104 if (length != 2) throw "Expected length for keySignature event is 2, got " + length;105 event.key = stream.readInt8(true);106 event.scale = stream.readInt8();107 return event;108 case 0x7f:109 event.subtype = 'sequencerSpecific';110 event.data = stream.read(length);111 return event;112 default:113 // console.log("Unrecognised meta event subtype: " + subtypeByte);114 event.subtype = 'unknown'115 event.data = stream.read(length);116 return event;117 }118 event.data = stream.read(length);119 return event;120 } else if (eventTypeByte == 0xf0) {121 event.type = 'sysEx';122 var length = stream.readVarInt();123 event.data = stream.read(length);124 return event;125 } else if (eventTypeByte == 0xf7) {126 event.type = 'dividedSysEx';127 var length = stream.readVarInt();128 event.data = stream.read(length);129 return event;130 } else {131 throw "Unrecognised MIDI event type byte: " + eventTypeByte;132 }133 } else {134 /* channel event */135 var param1;136 if ((eventTypeByte & 0x80) == 0) {137 /* running status - reuse lastEventTypeByte as the event type.138 eventTypeByte is actually the first parameter139 */140 param1 = eventTypeByte;141 eventTypeByte = lastEventTypeByte;142 } else {143 param1 = stream.readInt8();144 lastEventTypeByte = eventTypeByte;145 }146 var eventType = eventTypeByte >> 4;147 event.channel = eventTypeByte & 0x0f;148 event.type = 'channel';149 switch (eventType) {150 case 0x08:151 event.subtype = 'noteOff';152 event.noteNumber = param1;153 event.velocity = stream.readInt8();154 return event;155 case 0x09:156 event.noteNumber = param1;157 event.velocity = stream.readInt8();158 if (event.velocity == 0) {159 event.subtype = 'noteOff';160 } else {161 event.subtype = 'noteOn';162 }163 return event;164 case 0x0a:165 event.subtype = 'noteAftertouch';166 event.noteNumber = param1;167 event.amount = stream.readInt8();168 return event;169 case 0x0b:170 event.subtype = 'controller';171 event.controllerType = param1;172 event.value = stream.readInt8();173 return event;174 case 0x0c:175 event.subtype = 'programChange';176 event.programNumber = param1;177 return event;178 case 0x0d:179 event.subtype = 'channelAftertouch';180 event.amount = param1;181 return event;182 case 0x0e:183 event.subtype = 'pitchBend';184 event.value = param1 + (stream.readInt8() << 7);185 return event;186 default:187 throw "Unrecognised MIDI event type: " + eventType188 /* 189 console.log("Unrecognised MIDI event type: " + eventType);190 stream.readInt8();191 event.subtype = 'unknown';192 return event;193 */194 }195 }196 }197 198 stream = Stream(data);199 var headerChunk = readChunk(stream);200 if (headerChunk.id != 'MThd' || headerChunk.length != 6) {201 throw "Bad .mid file - header not found";202 }203 var headerStream = Stream(headerChunk.data);204 var formatType = headerStream.readInt16();...
123.js
Source:123.js
...27console.log(buffer.readUInt8(18))28console.log(buffer.readUInt8(19))29// SN char 1030console.log("SN", buffer.slice(20, 30).toString())31console.log(buffer.readInt8(20))32console.log(buffer.readInt8(21))33console.log(buffer.readInt8(22))34console.log(buffer.readInt8(23))35console.log(buffer.readInt8(24))36console.log(buffer.readInt8(25))37console.log(buffer.readInt8(26))38// 软件çæ¬ char 1039console.log("软件çæ¬", buffer.slice(20, 30).toString("ascii"))40console.log("软件çæ¬", buffer.slice(20, 30).toString("utf8"))41console.log("软件çæ¬", buffer.slice(20, 30).readInt8(0))42console.log("软件çæ¬", buffer.slice(20, 30).readInt8(1))43console.log("软件çæ¬", buffer.slice(20, 30).readInt8(2))44console.log("软件çæ¬", buffer.slice(20, 30).readInt8(3))45console.log("软件çæ¬", buffer.slice(20, 30).readInt8(4))46console.log("软件çæ¬", buffer.slice(20, 30).readInt8(5))47console.log("软件çæ¬", buffer.slice(20, 30).readInt8(6))48console.log("软件çæ¬", buffer.slice(20, 30).readInt8(7))49console.log("软件çæ¬", buffer.slice(20, 30).readInt8(8))50// 硬件çæ¬ char 10 byte1ï¼RSRP ï¼ byte2ï¼RSRQ51console.log("硬件çæ¬", buffer.slice(30, 40).toString("ascii"))52console.log("硬件çæ¬", buffer.slice(30, 40).toString("utf8"))53console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(0))54console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(1))55console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(2))56console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(3))57console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(4))58console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(5))59console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(6))60console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(7))61console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(8))62console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(9))63// console.log("硬件çæ¬", buffer.slice(30, 40).readInt8(10))64// RSSI signed char 165console.log("RSSI", buffer.readInt8(41))66// çµå float 467console.log("çµå", buffer.readFloatLE(42))68// çµæµ float 469console.log("çµæµ", buffer.readFloatLE(46))70// å
é» float 471console.log("å
é»", buffer.readFloatLE(50))72// 温度 signed char 1 ä¼ æå¨æ¸©åº¦73console.log("温度", buffer.readInt8(54))74console.log(buffer.slice(0, 50))75console.log(buffer.slice(50, 100))76console.log(buffer.slice(100, 150))77console.log(buffer.slice(150, 200))78console.log(buffer.slice(200, 250))79console.log(buffer.slice(250, 300))80console.log(buffer.slice(300, 350))81console.log(buffer.slice(350, 400))82console.log(buffer.slice(400, 450))...
index.js
Source:index.js
...6 console.log(name);7 run();8}9test('positive 32-bit', function () {10 assert.strictEqual(readInt8(bufferFrom([0, 0, 0, 0, 0, 0, 0, 0])), '0');11 assert.strictEqual(readInt8(bufferFrom([0, 0, 0, 0, 0, 0, 0, 1])), '1');12 assert.strictEqual(readInt8(bufferFrom([0, 0, 0, 0, 0, 0, 2, 0])), '512');13 assert.strictEqual(readInt8(bufferFrom([0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff])), '4294967295');14});15test('negative 32-bit', function () {16 assert.strictEqual(readInt8(bufferFrom([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])), '-1');17 assert.strictEqual(readInt8(bufferFrom([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00])), '-512');18 assert.strictEqual(readInt8(bufferFrom([0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00])), '-4294967296');19});20test('positive 64-bit', function () {21 assert.strictEqual(readInt8(bufferFrom([0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])), '9007199254740991');22 assert.strictEqual(readInt8(bufferFrom([0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])), '9223372036854775807');23 assert.strictEqual(readInt8(bufferFrom([0x00, 0x00, 0x00, 0x02, 0x54, 0x0b, 0xe4, 0x00])), '10000000000');24 assert.strictEqual(readInt8(bufferFrom([0x00, 0x00, 0x00, 0x17, 0x48, 0x76, 0xe8, 0x01])), '100000000001');25 assert.strictEqual(readInt8(bufferFrom([0x0d, 0xe0, 0xb6, 0xb3, 0xa7, 0x64, 0x00, 0x63])), '1000000000000000099');26});27test('negative 64-bit', function () {28 assert.strictEqual(readInt8(bufferFrom([0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), '-9007199254740991');29 assert.strictEqual(readInt8(bufferFrom([0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])), '-9223372036854775808');30 assert.strictEqual(readInt8(bufferFrom([0xff, 0xff, 0xff, 0xe8, 0xb7, 0x89, 0x18, 0x00])), '-100000000000');31 assert.strictEqual(readInt8(bufferFrom([0xff, 0xff, 0xff, 0xfd, 0xab, 0xf4, 0x1b, 0xff])), '-10000000001');32 assert.strictEqual(readInt8(bufferFrom([0xf2, 0x1f, 0x49, 0x4c, 0x58, 0x9b, 0xff, 0x9d])), '-1000000000000000099');...
Using AI Code Generation
1var wpt = require('wpt');2var buf = new Buffer(256);3buf.fill(0);4var len = buf.write('\u00bd + \u00bc = \u00be', 0);5console.log('Octets written : ' + len);6for (var i = 0 ; i < 26 ; i++) {7 console.log(buf.readInt8(i));8}9var wpt = require('wpt');10var buf = new Buffer(256);11buf.fill(0);12var len = buf.write('\u00bd + \u00bc = \u00be', 0);13console.log('Octets written : ' + len);14for (var i = 0 ; i < 26 ; i += 2) {15 console.log(buf.readInt16LE(i));16}17var wpt = require('wpt');18var buf = new Buffer(256);19buf.fill(0);20var len = buf.write('\u00bd + \u00bc = \u00be', 0);21console.log('Octets written : ' + len);22for (var i = 0 ; i < 26 ; i += 2) {23 console.log(buf.readInt16BE(i));24}25var wpt = require('wpt');26var buf = new Buffer(256);27buf.fill(0);28var len = buf.write('\u00bd + \u00bc = \u00be', 0);29console.log('Octets written : ' + len);30for (var i = 0 ; i < 26 ; i += 4) {31 console.log(buf.readInt32LE(i));32}33var wpt = require('wpt');34var buf = new Buffer(256);35buf.fill(0);36var len = buf.write('\u00bd + \u00bc = \u00be', 0);37console.log('Octets written : ' + len);38for (var i = 0 ; i < 26 ; i += 4) {39 console.log(buf.readInt32BE(i));40}
Using AI Code Generation
1var wpt = require('wpt');2var fs = require('fs');3var fd = fs.openSync('./test.txt', 'r');4var buf = new Buffer(1);5fs.readSync(fd, buf, 0, 1, 0);6console.log(buf.readInt8(0));7fs.closeSync(fd);8var wpt = require('wpt');9var fs = require('fs');10var fd = fs.openSync('./test.txt', 'r');11var buf = new Buffer(2);12fs.readSync(fd, buf, 0, 2, 0);13console.log(buf.readInt16BE(0));14fs.closeSync(fd);15var wpt = require('wpt');16var fs = require('fs');17var fd = fs.openSync('./test.txt', 'r');18var buf = new Buffer(2);19fs.readSync(fd, buf, 0, 2, 0);20console.log(buf.readInt16LE(0));21fs.closeSync(fd);22var wpt = require('wpt');23var fs = require('fs');24var fd = fs.openSync('./test.txt', 'r');25var buf = new Buffer(4);26fs.readSync(fd, buf, 0, 4, 0);27console.log(buf.readInt32BE(0));28fs.closeSync(fd);29var wpt = require('wpt');30var fs = require('fs');31var fd = fs.openSync('./test.txt', 'r');32var buf = new Buffer(4);33fs.readSync(fd, buf, 0, 4, 0);34console.log(buf.readInt32LE(0));35fs.closeSync(fd
Using AI Code Generation
1var wpt = require('wpt');2var fs = require('fs');3var buf = new Buffer(256);4var fd = fs.openSync('test.txt', 'r');5wpt.readInt8(fd, buf, 0, 256, 0, function(err, bytesRead, buffer) {6 if (err) {7 console.log('Error: ' + err);8 } else {9 console.log('Bytes read: ' + bytesRead);10 console.log('Buffer: ' + buffer);11 }12});13var wpt = require('wpt');14var fs = require('fs');15var buf = new Buffer(256);16var fd = fs.openSync('test.txt', 'r');17wpt.readInt8(fd, buf, 0, 256, 0, function(err, bytesRead, buffer) {18 if (err) {19 console.log('Error: ' + err);20 } else {21 console.log('Bytes read: ' + bytesRead);22 console.log('Buffer: ' + buffer);23 }24});25var wpt = require('wpt');26var fs = require('fs');27var buf = new Buffer(256);28var fd = fs.openSync('test.txt', 'r');29wpt.readInt8(fd, buf, 0, 256, 0, function(err, bytesRead, buffer) {30 if (err) {31 console.log('Error: ' + err);32 } else {33 console.log('Bytes read: ' + bytesRead);34 console.log('Buffer: ' + buffer);35 }36});37var wpt = require('wpt');38var fs = require('fs');39var buf = new Buffer(256);40var fd = fs.openSync('test.txt', 'r');41wpt.readInt8(fd, buf, 0, 256, 0, function(err, bytesRead, buffer) {42 if (err) {43 console.log('Error: ' + err);44 } else {45 console.log('Bytes read: ' + bytesRead);46 console.log('Buffer: ' + buffer);47 }48});
Using AI Code Generation
1var wptoolkit = require('./wptoolkit.js');2var fs = require('fs');3var fd = fs.openSync('test.bin', 'r');4var buffer = new Buffer(1);5fs.readSync(fd, buffer, 0, 1, 0);6var result = wptoolkit.readInt8(buffer, 0);7console.log(result);8fs.closeSync(fd);
Using AI Code Generation
1var wpt = require('wpt');2var fs = require('fs');3var path = require('path');4var file = fs.readFileSync(path.join(__dirname, 'test.bin'));5var value = wpt.readInt8(file, 0);6wpt.writeInt8(file, 4, 0);7wpt.readInt16LE(file, 0);8wpt.writeInt16LE(file, 1028, 0);9wpt.readInt16BE(file, 0);10wpt.writeInt16BE(file, 5, 0);11wpt.readInt32LE(file, 0);12wpt.writeInt32LE(file, 6, 0);13wpt.readInt32BE(file, 0);14wpt.writeInt32BE(file, 7, 0);15wpt.readFloatLE(file, 0);16wpt.writeFloatLE(file, 8, 0);17wpt.readFloatBE(file, 0);18wpt.writeFloatBE(file, 9, 0);19wpt.readDoubleLE(file, 0);
Using AI Code Generation
1var wpt = require('wptoolkit');2var wp = new wpt();3wp.readInt8(0x1000, function(err, data) {4 if (err) {5 console.log(err);6 }7 else {8 console.log("data read is " + data);9 }10});
Using AI Code Generation
1var wptools = require('wptools');2var wiki = wptools('Albert Einstein');3wiki.get(function(err, data) {4 console.log(data);5});6[MIT](
Using AI Code Generation
1var wpt = require('wpt');2var wptObj = new wpt();3var fd = wptObj.openSync('test.txt', 'r');4var buf = new Buffer(1);5var bytesRead = wptObj.readSync(fd, buf, 0, 1, 0);6console.log("bytes read: " + bytesRead);7console.log("buffer data: " + buf.toString('utf8'));8wptObj.closeSync(fd);9var wpt = require('wpt');10var wptObj = new wpt();11var fd = wptObj.openSync('test.txt', 'r');12var buf = new Buffer(1);13wptObj.read(fd, buf, 0, 1, 0, function(err, bytesRead, buffer) {14 if (err) throw err;15 console.log("bytes read: " + bytesRead);16 console.log("buffer data: " + buffer.toString('utf8'));17});18wptObj.closeSync(fd);19var wpt = require('wpt');20var wptObj = new wpt();21var fd = wptObj.openSync('test.txt', 'r');22var buf = new Buffer(2);23var bytesRead = wptObj.readSync(fd, buf, 0, 2, 0);24console.log("bytes read: " + bytesRead);25console.log("buffer data: " + buf.readInt16LE(0));26wptObj.closeSync(fd);27var wpt = require('wpt');28var wptObj = new wpt();29var fd = wptObj.openSync('test.txt',
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!!