Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/canvaseno/deps.ts>Buffer#write

Canvas API for deno
Latest
method Buffer.prototype.write
import { Buffer } from "https://deno.land/x/canvaseno@v1.0.2/deps.ts";

Writes string to buf at offset according to the character encoding inencoding. The length parameter is the number of bytes to write. If buf did not contain enough space to fit the entire string, only part of string will be written. However, partially encoded characters will not be written.

import { Buffer } from 'buffer';

const buf = Buffer.alloc(256);

const len = buf.write('\u00bd + \u00bc = \u00be', 0);

console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
// Prints: 12 bytes: ½ + ¼ = ¾

const buffer = Buffer.alloc(10);

const length = buffer.write('abcd', 8);

console.log(`${length} bytes: ${buffer.toString('utf8', 8, 10)}`);
// Prints: 2 bytes : ab

Parameters

string: string

String to write to buf.

optional
encoding: Encoding

Returns

number

Number of bytes written.

Parameters

string: string
offset: number
optional
encoding: Encoding

Returns

number

Parameters

string: string
offset: number
length: number
optional
encoding: Encoding

Returns

number