convert bytes to string node.js code example

Example: bytes to string js

const axios = require('axios')

function serializeBytes(sty) {
	const string = JSON.stringify({ data: sty })
	const input = Array.from(string)
	const ouput = input.map((_, i) => string.charCodeAt(i))
	return new Uint8Array(ouput)
}

function deserializeBytes(array) {
	return new TextDecoder().decode(array)
}

// render 25.000 data no maximum call stack
async function httpRequest() {
	const resOne = await axios.get('https://jsonplaceholder.typicode.com/photos')
	const resTwo = await axios.get('https://jsonplaceholder.typicode.com/photos')
	const resThree = await axios.get('https://jsonplaceholder.typicode.com/photos')
	const resFour = await axios.get('https://jsonplaceholder.typicode.com/photos')
	const resFive = await axios.get('https://jsonplaceholder.typicode.com/photos')
	const data = await Promise.all([resOne.data, resTwo.data, resThree.data, resFour.data, resFive.data])

	const encoded = serializeBytes(JSON.stringify({ data: data }))
	const decoded = deserializeBytes(encoded)
	const parse = JSON.parse(decoded)
	console.log(parse)
}

httpRequest()

Tags:

Misc Example