From 2e1fbec54bdeaf0c0bfbd9c0f76fefac958aae3f Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 29 Sep 2024 00:25:02 +0200 Subject: [PATCH] Add copyFrom/copyTo and zeroFill apis in NativePointer --- typescript/async/r2papi.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/typescript/async/r2papi.ts b/typescript/async/r2papi.ts index eb4fbd1..f043f23 100644 --- a/typescript/async/r2papi.ts +++ b/typescript/async/r2papi.ts @@ -882,6 +882,32 @@ export class NativePointer { this.api = api?? R; this.addr = ("" + s).trim(); } + /** + * Copy N bytes from current pointer to the destination + * + * @param {string|NativePointer|number} destination address + * @param {string|number} amount of bytes + */ + async copyTo(addr: string|NativePointer|number, size: string|number) : Promise { + this.api.call(`wf ${this.addr} ${size} @ ${addr}`) + } + /** + * Copy N bytes from given address to the current destination + * + * @param {string|NativePointer|number} source address + * @param {string|number} amount of bytes + */ + async copyFrom(addr: string|NativePointer|number, size: string|number) : Promise { + this.api.call(`wf ${addr} ${size} @ ${this.addr}`) + } + /** + * Fill N bytes in this address with zero + * + * @param {string|number} amount of bytes + */ + async zeroFill(size: string|number) : Promise { + this.api.call(`w0 ${size} @ ${this.addr}`) + } /** * Filter a string to be used as a valid flag name *