Skip to content

Instantly share code, notes, and snippets.

View SourceBoy's full-sized avatar
🏠
Working from home

SourceBoy

🏠
Working from home
View GitHub Profile
@SourceBoy
SourceBoy / translate-streams.js
Created March 21, 2023 06:03
WHATWG ReadableStream <-> Node stream.Readable
/**
* WHATWG ReadableStream <-> Node stream.Readable
* @author SourceBoy
* @license MIT
*/
/**
* WHATWG ReadableStream to Node stream.Readable
* @param {ReadableStream} rs
* @returns {stream.Readable}
@SourceBoy
SourceBoy / hash.js
Last active April 25, 2022 02:57
Web Crypto Hashing
/**
* sha256
* @param {string} [input='']
* @param {string} [algorithm='SHA-256']
* @returns {Promise<string>}
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest}
* @author SourceBoy
* @license MIT
*/
async function sha256(input = '', algorithm = 'SHA-256') {
@SourceBoy
SourceBoy / run-length-encode.js
Created March 17, 2021 23:27
Run Length Encoding
/**
* Run Length Encoding
* @author SourceBoy
* @license MIT
*/
function runlengthEncode(input = '') {
const chars = input.split('').concat([' ']);
const out = [];
let [current] = chars;
@SourceBoy
SourceBoy / translate-stream.js
Created January 27, 2021 20:40
Translate ReadableStreamDefaultReader to Node.js stream.Readable
/**
* Translate ReadableStreamDefaultReader to Node.js stream.Readable
* @author SourceBoy
* @license MIT
*/
async function pump(rs, _rs) {
const { done, value } = await rs.read();
if (done) {
_rs.push(null);