How to use toBuffer method in ava

Best JavaScript code snippet using ava

queryrecent.js

Source:queryrecent.js Github

copy

Full Screen

...149 res.on("data", chunk => {150 beatimg.push(chunk);151 });152 res.on("end", () => {153 sharp(Buffer.concat(beatimg)).toBuffer((err, data, info) => {154 if(err) resolve(err);155 else resolve(data);156 });157 });158 res.on("error", err => {159 resolve(err);160 });161 }).on('error', function (err) {162 resolve(err);163 });164 });165 166 // 传递参数到下一个环节167 return Promise168 .all([169 transfer_username,170 transfer_recent,171 get_beatmaps_func,172 get_beatmapimg_func173 ]).catch(err => {174 return err175 });176 })177 .then(result => {// 合成recent快照178 if(result.toString().indexOf('Error') > -1){179 return result;180 }181 let username = result[0];182 let recent = result[1];183 let beatmap = JSON.parse(result[2])[0];184 let backimg = result[3];185 186 // 载入beatmap背景图187 let recentimg = backimg.toString().startsWith('[sharpErr]') ? sharp(skin['defaultbg']) : sharp(backimg);188 189 // 设置画布尺寸190 let canvasW = 1366;191 let canvasH = 768;192 let zoomval = canvasH/600;193 // 创建原始尺寸绘图容器194 const frame = new Buffer.from(`<svg width="800" height="600"></svg>`); 195 // 设置画布遮罩196 const mask = new Buffer.from( 197 `<svg width="${canvasW}" height="${canvasH}">198 <rect x="0" y="0" width="${canvasW}" height="${canvasH}" fill="#000" fill-opacity="0.4"/>199 <rect x="0" y="0" width="${canvasW}" height="${75*zoomval}" fill="#000" fill-opacity="0.8"/>200 </svg>`201 );202 // 设置标题文字203 const title = new Buffer.from(204 `<svg width="800" height="600">205 <text class="h1" x="3" y="${1+17}" font-family="Aller Light" font-size="16.92" fill="#FFF">206 ${beatmap["artist"]} - ${beatmap["title"]} [${beatmap["version"]}]207 </text>208 <text class="h2" x="3" y="${26+12}" font-family="Aller" font-size="12.3" fill="#FFF">209 Beatmap by ${beatmap["creator"]}210 </text>211 <text class="h3" x="3" y="${45+13}" font-family="Microsoft YaHei UI" font-size="12.9" fill="#FFF">212 Played by ${username} on ${recent["date"].toString() .replace(/-/g, '/')}.213 </text>214 </svg>`215 );216 // 绘制画布背景217 let canvas = new Promise((resolve, reject) => {218 sharp(mask).toBuffer()219 .then(buff => {// 添加背景图片220 return recentimg.resize(canvasW, canvasH).toBuffer()221 .then(buf => {222 return sharp(buf).overlayWith(buff).toBuffer();223 });224 })225 .then(buff => {// 叠加 ranking-panel 图片226 return sharp(skin['ranking-panel']).toBuffer({ resolveWithObject: true })227 .then(res => {228 let imgW = Math.round(res.info.width*zoomval*0.78);229 let imgH = Math.round(res.info.height*zoomval*0.78);230 let cutW = imgW > canvasW ? canvasW : imgW;231 let cutH = imgH > (canvasH - Math.round(80*zoomval)) ? (canvasH - Math.round(80*zoomval)) : imgH;232 return sharp(res.data).resize(imgW, imgH).extract({left:0, top:0, width:cutW, height:cutH}).toBuffer()233 .then(buf => {234 return sharp(buff).overlayWith(buf, {top: Math.round(80*zoomval), left: 0}).toBuffer();235 });236 });237 })238 .then(buff => {// 叠加 menu-back 图片239 return sharp(skin['menu-back']).toBuffer({ resolveWithObject: true })240 .then(res => {241 let imgW = Math.round(res.info.width*zoomval*0.8);242 let imgH = Math.round(res.info.height*zoomval*0.8);243 return sharp(res.data).resize(imgW, imgH).toBuffer()244 .then(buf => {245 return sharp(buff).overlayWith(buf, {gravity: sharp.gravity.southwest}).toBuffer();246 });247 });248 })249 .then(buff => {// 叠加 ranking-graph 图片250 return sharp(skin['ranking-graph']).toBuffer({ resolveWithObject: true })251 .then(res => {252 let imgW = Math.round(res.info.width*zoomval*0.78);253 let imgH = Math.round(res.info.height*zoomval*0.78);254 let maxH = imgH > Math.round(125*zoomval) ? Math.round(125*zoomval) : imgH;255 return sharp(res.data).resize(imgW, imgH)256 .extract({left:0, top:0, width: imgW, height: maxH }).toBuffer()257 .then(buf => {258 return sharp(buff).overlayWith(buf, {259 left: Math.round(200*zoomval),260 top: Math.round(475*zoomval)261 }).toBuffer();262 });263 });264 })265 .then(buff => {// 叠加 hit[300,100,50,300g,100k,0] 图片266 return new Promise((resolve1, reject1) => { resolve1(buff); })267 .then(buf => {// 叠加 hit300 图片268 return sharp(skin['hit300']).toBuffer({ resolveWithObject: true }).then(res => {269 let imgW = Math.round(res.info.width*zoomval*0.4);270 let imgH = Math.round(res.info.height*zoomval*0.4);271 let imgX = Math.round(50*zoomval-imgW/2<0 ? 0 : 50*zoomval-imgW/2);// sharp不允许覆盖的图片超出画布272 let imgY = Math.round(200*zoomval-imgH/2);273 return sharp(res.data).resize(imgW, imgH).toBuffer().then(b => {274 return sharp(buf).overlayWith(b, {left:imgX, top:imgY}).toBuffer();275 });276 });277 })278 .then(buf => {// 叠加 hit100 图片279 return sharp(skin['hit100']).toBuffer({ resolveWithObject: true }).then(res => {280 let imgW = Math.round(res.info.width*zoomval*0.4);281 let imgH = Math.round(res.info.height*zoomval*0.4);282 let imgX = Math.round(50*zoomval-imgW/2<0 ? 0 : 50*zoomval-imgW/2);283 let imgY = Math.round(275*zoomval-imgH/2);284 return sharp(res.data).resize(imgW, imgH).toBuffer().then(b => {285 return sharp(buf).overlayWith(b, {left:imgX, top:imgY}).toBuffer();286 });287 });288 })289 .then(buf => {// 叠加 hit50 图片290 return sharp(skin['hit50']).toBuffer({ resolveWithObject: true }).then(res => {291 let imgW = Math.round(res.info.width*zoomval*0.4);292 let imgH = Math.round(res.info.height*zoomval*0.4);293 let imgX = Math.round(50*zoomval-imgW/2<0 ? 0 : 50*zoomval-imgW/2);294 let imgY = Math.round(350*zoomval-imgH/2);295 return sharp(res.data).resize(imgW, imgH).toBuffer().then(b => {296 return sharp(buf).overlayWith(b, {left:imgX, top:imgY}).toBuffer();297 });298 });299 })300 .then(buf => {// 叠加 hit300g 图片301 return sharp(skin['hit300g']).toBuffer({ resolveWithObject: true }).then(res => {302 let imgW = Math.round(res.info.width*zoomval*0.4);303 let imgH = Math.round(res.info.height*zoomval*0.4);304 let imgX = Math.round(300*zoomval-imgW/2<0 ? 0 : 300*zoomval-imgW/2);305 let imgY = Math.round(200*zoomval-imgH/2);306 return sharp(res.data).resize(imgW, imgH).toBuffer().then(b => {307 return sharp(buf).overlayWith(b, {left:imgX, top:imgY}).toBuffer();308 });309 });310 })311 .then(buf => {// 叠加 hit100k 图片312 return sharp(skin['hit100k']).toBuffer({ resolveWithObject: true }).then(res => {313 let imgW = Math.round(res.info.width*zoomval*0.4);314 let imgH = Math.round(res.info.height*zoomval*0.4);315 let imgX = Math.round(300*zoomval-imgW/2<0 ? 0 : 300*zoomval-imgW/2);316 let imgY = Math.round(275*zoomval-imgH/2);317 return sharp(res.data).resize(imgW, imgH).toBuffer().then(b => {318 return sharp(buf).overlayWith(b, {left:imgX, top:imgY}).toBuffer();319 });320 });321 })322 .then(buf => {// 叠加 hit0 图片323 return sharp(skin['hit0']).toBuffer({ resolveWithObject: true }).then(res => {324 let imgW = Math.round(res.info.width*zoomval*0.4);325 let imgH = Math.round(res.info.height*zoomval*0.4);326 let imgX = Math.round(300*zoomval-imgW/2<0 ? 0 : 300*zoomval-imgW/2);327 let imgY = Math.round(350*zoomval-imgH/2);328 return sharp(res.data).resize(imgW, imgH).toBuffer().then(b => {329 return sharp(buf).overlayWith(b, {left:imgX, top:imgY}).toBuffer();330 });331 });332 });333 })334 .then(buff => {// 叠加 ranking-maxcombo 图片335 return sharp(skin['ranking-maxcombo']).toBuffer({ resolveWithObject: true }).then(res => {336 let imgW = Math.round(res.info.width*zoomval*0.78);337 let imgH = Math.round(res.info.height*zoomval*0.78);338 let imgX = Math.round(6*zoomval);339 let imgY = Math.round(375*zoomval);340 return sharp(res.data).resize(imgW, imgH).toBuffer().then(buf => {341 return sharp(buff).overlayWith(buf, {left:imgX, top:imgY}).toBuffer();342 });343 });344 })345 .then(buff => {// 叠加 ranking-accuracy 图片346 return sharp(skin['ranking-accuracy']).toBuffer({ resolveWithObject: true }).then(res => {347 let imgW = Math.round(res.info.width*zoomval*0.78);348 let imgH = Math.round(res.info.height*zoomval*0.78);349 let imgX = Math.round(228*zoomval);350 let imgY = Math.round(375*zoomval);351 return sharp(res.data).resize(imgW, imgH).toBuffer().then(buf => {352 return sharp(buff).overlayWith(buf, {left:imgX, top:imgY}).toBuffer();353 });354 });355 })356 .then(buff => {// 叠加 network 图片357 return sharp(buff).overlayWith(skin['network'], {gravity: sharp.gravity.southeast}).toBuffer();358 })359 .then(buff => {360 resolve(buff);361 });362 });363 // 绘制结算界面左边部分364 let frameLeft = new Promise((resolve, reject) => {365 sharp(frame).toBuffer()366 .then(buff => {// 叠加 ranking-perfect367 if(Number(recent['perfect']) !== 1) return buff;368 return sharp(skin['ranking-perfect']).toBuffer({ resolveWithObject: true })369 .then(res => {370 let imgW = Math.round(res.info.width*0.78); let imgH = Math.round(res.info.height*0.78);371 return sharp(res.data).resize(imgW, imgH).toBuffer()372 .then(buf => {373 return sharp(buff).overlayWith(buf, {374 left:Math.round(325-imgW/2), 375 top:Math.round(537-imgH/2)376 }).toBuffer();377 })378 });379 })380 .then(buff => {// 叠加 score381 let scoreval = recent['score'];382 if(scoreval.length < 8) scoreval = '00000000'.slice(scoreval.length) + scoreval;383 return new Promise((resolve1, reject1) => {384 sharp(skin[`score-0`]).toBuffer((err, data, info) => {385 const scoreW = info.width;386 const scoreH = info.height;387 const spacing = 3;388 const scorebar = new Buffer.from(389 `<svg width="${scoreval.length*(scoreW+spacing)-spacing}" height="${scoreH}"></svg>`390 );391 (function sive(buf, i){392 if(i === scoreval.length){393 sharp(buff).overlayWith(buf, {394 left: Math.round(274-((scoreval.length*(scoreW+spacing)-spacing)/2)), 395 top: Math.round(117-(scoreH/2))396 }).toBuffer().then(b => {397 resolve1(b);398 });399 }else{400 let scorechar = skin[`score-${scoreval.charAt(i)}`];401 sharp(buf)402 .overlayWith(scorechar, {left: i*(scoreW+spacing), top: 0})403 .toBuffer()404 .then(b =>{ sive(b, i+1); });405 }406 })(scorebar, 0);407 });408 });409 })410 .then(buff => {// 叠加 count411 return sharp(skin['score-0']).toBuffer({ resolveWithObject: true })412 .then(res => {413 let comboW = Math.round(res.info.width*0.9); let comboH = Math.round(res.info.height*0.9);414 return new Promise((resolve1, reject1) => { resolve1(buff); })415 .then(buf => {// 叠加 count300416 let countval = recent['count300'] + 'x';417 return (function sive(bf, i){418 if(i === countval.length){419 return bf;420 }else{421 let countchar = skin[`score-${countval.charAt(i)}`];422 return sharp(bf).overlayWith(countchar, {423 left:100+i*comboW, 424 top:Math.round(200-comboH/2)425 }).toBuffer().then(b =>{ return sive(b, i+1); });426 }427 })(buf, 0);428 })429 .then(buf => {// 叠加 count100430 let countval = recent['count100'] + 'x';431 return (function sive(bf, i){432 if(i === countval.length){433 return bf;434 }else{435 let countchar = skin[`score-${countval.charAt(i)}`];436 return sharp(bf).overlayWith(countchar, {437 left:100+i*comboW, 438 top:Math.round(275-comboH/2)439 }).toBuffer().then(b =>{ return sive(b, i+1); });440 }441 })(buf, 0);442 })443 .then(buf => {// 叠加 count50444 let countval = recent['count50'] + 'x';445 return (function sive(bf, i){446 if(i === countval.length){447 return bf;448 }else{449 let countchar = skin[`score-${countval.charAt(i)}`];450 return sharp(bf).overlayWith(countchar, {451 left:100+i*comboW, 452 top:Math.round(350-comboH/2)453 }).toBuffer().then(b =>{ return sive(b, i+1); });454 }455 })(buf, 0);456 })457 .then(buf => {// 叠加 count300g (countgeki)458 let countval = recent['countgeki'] + 'x';459 return (function sive(bf, i){460 if(i === countval.length){461 return bf;462 }else{463 let countchar = skin[`score-${countval.charAt(i)}`];464 return sharp(bf).overlayWith(countchar, {465 left:350+i*comboW, 466 top:Math.round(200-comboH/2)467 }).toBuffer().then(b =>{ return sive(b, i+1); });468 }469 })(buf, 0);470 })471 .then(buf => {// 叠加 count100k (countkatu)472 let countval = recent['countkatu'] + 'x';473 return (function sive(bf, i){474 if(i === countval.length){475 return bf;476 }else{477 let countchar = skin[`score-${countval.charAt(i)}`];478 return sharp(bf).overlayWith(countchar, {479 left:350+i*comboW, 480 top:Math.round(275-comboH/2)481 }).toBuffer().then(b =>{ return sive(b, i+1); });482 }483 })(buf, 0);484 })485 .then(buf => {// 叠加 count0 (countmiss)486 let countval = recent['countmiss'] + 'x';487 return (function sive(bf, i){488 if(i === countval.length){489 return bf;490 }else{491 let countchar = skin[`score-${countval.charAt(i)}`];492 return sharp(bf).overlayWith(countchar, {493 left:350+i*comboW, 494 top:Math.round(350-comboH/2)495 }).toBuffer().then(b =>{ return sive(b, i+1); });496 }497 })(buf, 0);498 })499 });500 })501 .then(buff => {// 叠加 MaxCombo502 let dataStr = recent['maxcombo'] + 'x';503 return (function sive(bf, i, strX){504 if(i === dataStr.length){505 return bf;506 }else{507 let charStr = dataStr.charAt(i);508 return sharp(skin[`score-${charStr}`]).toBuffer({ resolveWithObject: true }).then(res => {509 let charW = Math.round(res.info.width*0.9); let charH = Math.round(res.info.height*0.9);510 return sharp(bf).overlayWith(res.data, {left:strX, top:412}).toBuffer()511 .then(b =>{ return sive(b, i+1, strX + charW); });512 });513 }514 })(buff, 0, 18);515 })516 .then(buff => {// 叠加 Accuracy517 let accuracy = (6*parseFloat(recent['count300']) + 2*parseFloat(recent['count100']) + parseFloat(recent['count50']))518 /(6*(parseFloat(recent['count300'])+parseFloat(recent['count100'])+parseFloat(recent['count50'])+parseFloat(recent['countmiss'])));519 let dataStr = Number(accuracy*100).toFixed(2) + '%';520 return (function sive(bf, i, strX){521 if(i === dataStr.length){522 return bf;523 }else{524 let charStr = dataStr.charAt(i);525 if (charStr == ".") charStr = "dot";526 if (charStr == "%") charStr = "percent";527 return sharp(skin[`score-${charStr}`]).toBuffer({ resolveWithObject: true }).then(res => {528 let charW = Math.round(res.info.width*0.9); let charH = Math.round(res.info.height*0.9);529 return sharp(bf).overlayWith(res.data, {left:strX, top:412}).toBuffer()530 .then(b =>{ return sive(b, i+1, strX + charW); });531 });532 }533 })(buff, 0, 242);534 })535 .then(buff => {// 缩放到合适尺寸输出536 sharp(buff).resize(null, canvasH).toBuffer()537 .then(buf => { resolve(buf); });538 });539 });540 //return new Promise((resolve, reject) => {541 // 绘制结算界面右边部分542 let frameRight = new Promise((resolve, reject) => {543 sharp(frame).toBuffer()544 .then(buff => {// 叠加 ranking-title545 return sharp(skin['ranking-title']).toBuffer({ resolveWithObject: true })546 .then(res => {547 let imgW = Math.round(res.info.width*0.78);548 let imgH = Math.round(res.info.height*0.78);549 let imgX = Math.round(800 - 25 - imgW);550 return sharp(res.data).resize(imgW, imgH).toBuffer()551 .then(buf => {552 return sharp(buff).overlayWith(buf, {left: imgX, top: 0 }).toBuffer();553 });554 });555 })556 .then(buff => {// 叠加 ranking 评价557 return sharp(skin[`ranking-${recent['rank'].toLowerCase()}`]).toBuffer({ resolveWithObject: true })558 .then(res => {559 let imgW = Math.round(res.info.width*0.78);560 let imgH = Math.round(res.info.height*0.78);561 let imgX = Math.round(800 - 150 - imgW/2);562 let imgY = Math.round(250 - imgH/2);563 return sharp(res.data).resize(imgW, imgH).toBuffer()564 .then(buf => {565 return sharp(buff).overlayWith(buf, {left: imgX, top: imgY}).toBuffer();566 });567 });568 })569 .then(buff => {// 叠加 Mods 图标570 let enabled_mods = recent['enabled_mods'];571 return (function sive(bf, i, strX){572 if(i === modnames.length){573 return bf;574 }else{575 if((enabled_mods & osumods[modnames[i]]) > 0){576 return sharp(skin[`selection-mod-${modnames[i].toLowerCase()}`])577 .toBuffer({ resolveWithObject: true})578 .then(res => {579 let imgW = Math.round(res.info.width*0.78);580 let imgH = Math.round(res.info.height*0.78);581 let imgX = Math.round(strX - imgW/2);582 let imgY = Math.round(325 - imgH/2);583 return sharp(bf).overlayWith(res.data, {left: imgX, top: imgY}).toBuffer()584 .then(b =>{ return sive(b, i+1, strX - imgW/2); });585 });586 }else{587 return sive(bf, i+1, strX);588 }589 }590 })(buff, 0, (800-50));591 })592 .then(buff => {// 叠加 pause-replay593 return sharp(skin[`pause-replay`]).toBuffer({ resolveWithObject: true })594 .then(res => {595 let imgW = Math.round(res.info.width*0.78);596 let imgH = Math.round(res.info.height*0.78);597 let imgX = Math.round(800 - imgW);598 let imgY = Math.round(450 - imgH/2);599 return sharp(res.data).resize(imgW, imgH).toBuffer()600 .then(buf => {601 return sharp(buff).overlayWith(buf, {left: imgX, top: imgY}).toBuffer();602 });603 });604 })605 .then(buff => {// 缩放到合适尺寸输出606 sharp(buff).resize(null, canvasH).toBuffer()607 .then(buf => { resolve(buf); });608 });609 });610 // 绘制标题栏部分611 let frameTitle = new Promise((resolve, reject) => {612 sharp(title).png().toBuffer()613 .then(buff => {// 缩放到合适尺寸输出614 sharp(buff).resize(null, canvasH).toBuffer()615 .then(buf => { resolve(buf); });616 });617 });618 619 // 组合recent结算快照620 return Promise621 .all([canvas, frameLeft, frameRight, frameTitle])622 .then(results => {623 return sharp(results[0]).toBuffer()624 .then(buff => {// 合成左边积分区域625 return sharp(buff).overlayWith(results[1], {gravity: sharp.gravity.west}).toBuffer();626 })627 .then(buff => {// 合成右边评价区域628 return sharp(buff).overlayWith(results[2], {gravity: sharp.gravity.east}).toBuffer();629 })630 .then(buff => {// 合成顶部标题区域631 return sharp(buff).overlayWith(results[3], {gravity: sharp.gravity.west}).toBuffer();632 })633 })634 .catch(err => {635 return err636 });637 })638 .catch(err => {// 捕获错误639 return err;640 });641};642module.exports = {643 get_recent...

Full Screen

Full Screen

errors.js

Source:errors.js Github

copy

Full Screen

...61 assertCompileError("X");62 assertCompileError("\0x00asm");63})();64(function TestValidationError() {65 assertCompileError(builder().addFunction("f", kSig_i_v).end().toBuffer());66 assertCompileError(builder().addFunction("f", kSig_i_v).addBody([67 kExprReturn68 ]).end().toBuffer());69 assertCompileError(builder().addFunction("f", kSig_v_v).addBody([70 kExprGetLocal, 071 ]).end().toBuffer());72 assertCompileError(builder().addStart(0).toBuffer());73})();74(function TestTypeError() {75 let b;76 b = builder();77 b.addImport("foo", "bar", kSig_v_v);78 assertTypeError(b.toBuffer(), {});79 b = builder();80 b.addImportedGlobal("foo", "bar", kWasmI32);81 assertTypeError(b.toBuffer(), {});82 b = builder();83 b.addImportedMemory("foo", "bar");84 assertTypeError(b.toBuffer(), {});85})();86(function TestLinkingError() {87 let b;88 b = builder();89 b.addImport("foo", "bar", kSig_v_v);90 assertLinkError(b.toBuffer(), {foo: {}});91 b = builder();92 b.addImport("foo", "bar", kSig_v_v);93 assertLinkError(b.toBuffer(), {foo: {bar: 9}});94 b = builder();95 b.addImportedGlobal("foo", "bar", kWasmI32);96 assertLinkError(b.toBuffer(), {foo: {}});97 b = builder();98 b.addImportedGlobal("foo", "bar", kWasmI32);99 assertLinkError(b.toBuffer(), {foo: {bar: ""}});100 b = builder();101 b.addImportedGlobal("foo", "bar", kWasmI32);102 assertLinkError(b.toBuffer(), {foo: {bar: () => 9}});103 b = builder();104 b.addImportedMemory("foo", "bar");105 assertLinkError(b.toBuffer(), {foo: {}});106 b = builder();107 b.addImportedMemory("foo", "bar", 1);108 assertLinkError(b.toBuffer(),109 {foo: {bar: () => new WebAssembly.Memory({initial: 0})}});110 b = builder();111 b.addFunction("startup", kSig_v_v).addBody([112 kExprUnreachable,113 ]).end().addStart(0);114 assertRuntimeError(b.toBuffer());115})();116(function TestTrapError() {117 assertRuntimeError(builder().addFunction("run", kSig_v_v).addBody([118 kExprUnreachable119 ]).exportFunc().end().toBuffer());120 assertRuntimeError(builder().addFunction("run", kSig_v_v).addBody([121 kExprI32Const, 1,122 kExprI32Const, 0,123 kExprI32DivS,124 kExprDrop125 ]).exportFunc().end().toBuffer());126 assertRuntimeError(builder().addFunction("run", kSig_v_v).addBody([127 ]).exportFunc().end().128 addFunction("start", kSig_v_v).addBody([129 kExprUnreachable130 ]).end().addStart(1).toBuffer());131})();132(function TestConversionError() {133 let b = builder();134 b.addImport("foo", "bar", kSig_v_l);135 assertConversionError(b.addFunction("run", kSig_v_v).addBody([136 kExprI64Const, 0, kExprCallFunction, 0137 ]).exportFunc().end().toBuffer(), {foo:{bar: (l)=>{}}});138 b = builder()139 assertConversionError(builder().addFunction("run", kSig_l_v).addBody([140 kExprI64Const, 0141 ]).exportFunc().end().toBuffer());...

Full Screen

Full Screen

buffer-utils.test.js

Source:buffer-utils.test.js Github

copy

Full Screen

2import { toBuffer } from './buffer-utils';3describe('buffer utils', function () {4 describe('toBuffer', function () {5 it('should work with prefixed hex strings', function () {6 const result = toBuffer('0xe');7 expect(result).toHaveLength(1);8 });9 it('should work with non prefixed hex strings', function () {10 const result = toBuffer('e');11 expect(result).toHaveLength(1);12 });13 it('should work with weirdly 0x prefixed non-hex strings', function () {14 const result = toBuffer('0xtest');15 expect(result).toHaveLength(6);16 });17 it('should work with regular strings', function () {18 const result = toBuffer('test');19 expect(result).toHaveLength(4);20 });21 it('should work with BN', function () {22 const result = toBuffer(new BN(100));23 expect(result).toHaveLength(1);24 });25 it('should work with Buffer', function () {26 const result = toBuffer(Buffer.from('test'));27 expect(result).toHaveLength(4);28 });29 it('should work with a number', function () {30 const result = toBuffer(100);31 expect(result).toHaveLength(1);32 });33 it('should work with null or undefined', function () {34 const result = toBuffer(null);35 const result2 = toBuffer(undefined);36 expect(result).toHaveLength(0);37 expect(result2).toHaveLength(0);38 });39 it('should work with UInt8Array', function () {40 const uint8 = new Uint8Array(2);41 const result = toBuffer(uint8);42 expect(result).toHaveLength(2);43 });44 it('should work with objects that have a toBuffer property', function () {45 const result = toBuffer({46 toBuffer: () => Buffer.from('hi'),47 });48 expect(result).toHaveLength(2);49 });50 it('should work with objects that have a toArray property', function () {51 const result = toBuffer({52 toArray: () => ['hi'],53 });54 expect(result).toHaveLength(1);55 });56 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createCanvas, loadImage } = require('canvas')2const canvas = createCanvas(200, 200)3const ctx = canvas.getContext('2d')4ctx.rotate(0.1)5ctx.fillText('Awesome!', 50, 100)6var text = ctx.measureText('Awesome!')7ctx.strokeStyle = 'rgba(0,0,0,0.5)'8ctx.beginPath()9ctx.lineTo(50, 102)10ctx.lineTo(50 + text.width, 102)11ctx.stroke()12loadImage('images/lime-cat.jpg').then((image) => {13 ctx.drawImage(image, 50, 0, 70, 70)14 console.log('<img src="' + canvas.toDataURL() + '" />')15})

Full Screen

Using AI Code Generation

copy

Full Screen

1const avatar = await message.author.displayAvatarURL({ format: "png" });2const image = await Canvas.loadImage(avatar);3const canvas = Canvas.createCanvas(image.width, image.height);4const ctx = canvas.getContext("2d");5ctx.drawImage(image, 0, 0, image.width, image.height);6const attachment = new Discord.MessageAttachment(7 canvas.toBuffer(),8);9message.channel.send(attachment);10const avatar = await message.author.displayAvatarURL({ format: "png" });11const image = await Canvas.loadImage(avatar);12const canvas = Canvas.createCanvas(image.width, image.height);13const ctx = canvas.getContext("2d");14ctx.drawImage(image, 0, 0, image.width, image.height);15const attachment = new Discord.MessageAttachment(16 canvas.toBuffer(),17);18message.channel.send(attachment);19const avatar = await message.author.displayAvatarURL({ format: "png" });20const image = await Canvas.loadImage(avatar);21const canvas = Canvas.createCanvas(image.width, image.height);22const ctx = canvas.getContext("2d");23ctx.drawImage(image, 0, 0, image.width, image.height);24const attachment = new Discord.MessageAttachment(25 canvas.toBuffer(),26);27message.channel.send(attachment);28const avatar = await message.author.displayAvatarURL({ format: "png" });29const image = await Canvas.loadImage(avatar);30const canvas = Canvas.createCanvas(image.width, image.height);31const ctx = canvas.getContext("2d");32ctx.drawImage(image, 0, 0, image.width, image.height);33const attachment = new Discord.MessageAttachment(34 canvas.toBuffer(),35);36message.channel.send(attachment);37const avatar = await message.author.displayAvatarURL({ format: "png" });38const image = await Canvas.loadImage(avatar);39const canvas = Canvas.createCanvas(image.width, image.height);40const ctx = canvas.getContext("2d

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require("fs");2const { MessageAttachment } = require("discord.js");3const { createCanvas, loadImage } = require("canvas");4const canvas = createCanvas(700, 250);5const ctx = canvas.getContext("2d");6const background = await loadImage("./images/background.png");7ctx.drawImage(background, 0, 0, canvas.width, canvas.height);8ctx.font = "30px sans-serif";9ctx.fillStyle = "#ffffff";10ctx.fillText("Hello World!", canvas.width / 2.5, canvas.height / 3);11const attachment = new MessageAttachment(canvas.toBuffer(), "welcome-image.png");12const embed = new MessageEmbed()13 .setTitle("Welcome to the server!")14 .setColor("#0099ff")15 .attachFiles(attachment)16message.channel.send(embed);

Full Screen

Using AI Code Generation

copy

Full Screen

1var avatar = require('avatar');2var buf = avatar.toBuffer();3var avatar = require('avatar');4var base64 = avatar.toBase64();5var avatar = require('avatar');6var dataURI = avatar.toDataURI();7var avatar = require('avatar');8var obj = avatar.toObject();9var avatar = require('avatar');10var stream = avatar.toStream();11var avatar = require('avatar');12avatar.toFile('/path/to/file', function (err) {13 if (err) {14 } else {15 }16});17var avatar = require('avatar');18var dataURL = avatar.toDataURL();19var avatar = require('avatar');20var blob = avatar.toBlob();21var avatar = require('avatar');22var canvas = avatar.toCanvas();

Full Screen

Using AI Code Generation

copy

Full Screen

1var Avatar = require('./models/avatar');2var mongoose = require('mongoose');3Avatar.findById('57b3f3b9c6f1b6d8e6c4b6e4', function(err, avatar) {4 if (err) {5 console.log(err);6 } else {7 avatar.toBuffer(function(err, buffer) {8 if (err) {9 console.log(err);10 } else {11 console.log(buffer);12 }13 });14 }15});16var Avatar = require('./models/avatar');17var mongoose = require('mongoose');18Avatar.findById('57b3f3b9c6f1b6d8e6c4b6e4', function(err, avatar) {19 if (err) {20 console.log(err);21 } else {22 avatar.toBuffer(function(err, buffer) {23 if (err) {24 console.log(err);25 } else {26 console.log(buffer);27 }28 });29 }30});31var Avatar = require('./models/avatar');32var mongoose = require('mongoose');33Avatar.findById('57b3f3b9c6f1b6d8e6c4b6e4', function(err, avatar) {34 if (err) {35 console.log(err);36 } else {37 avatar.toBuffer(function(err, buffer) {38 if (err) {39 console.log(err);40 } else {41 console.log(buffer);42 }43 });44 }45});46var Avatar = require('./models/avatar');47var mongoose = require('mongoose');48Avatar.findById('57

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 ava 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