Créez des tampons à partir de chaînes à l'aide de la fonction tampon.from (). Comme toString (), vous pouvez passer un argument de codage à tampon.from ().

let buf = Buffer.from('Hello, World', 'utf8');

buf.toString('hex'); // '48656c6c6f2c20576f726c64'
buf.toString('utf8'); // 'Hello, World'

buf = Buffer.from('48656c6c6f2c20576f726c64', 'hex');
buf.toString('utf8'); // 'Hello, World'
CL