Azion Runtime and Node.js API compatibility - String Decoder
The string_decoder
module in Node.js provides a way to decode buffer objects into strings. It’s particularly useful when working with streams of binary data, allowing developers to convert raw binary data into readable strings while handling different character encodings.
/** * An example of using Node.js StringDecoder API in an Azion Edge Function. * Support: * - Partially supported (Extended by library `string_decoder`) * @module runtime-apis/nodejs/string-decoder/main * @example * // Execute with Azion Bundler: * npx edge-functions build * npx edge-functions dev */import string_decoder from "node:string_decoder";
/** * An example of using the Node.js StringDecoder API in an Azion Edge Function. * @param {*} event * @returns {Promise<Response>} */const main = async (event) => { const decoder = new string_decoder.StringDecoder("utf8"); const buffer = Buffer.from([0xc2, 0xa2]); const decoded = decoder.write(buffer); console.log(decoded); // ¢
return new Response(decoded, { status: 200 });};
export default main;
Contributors