diff --git a/buffer/buffer.ts b/buffer/buffer.ts index c10433e1bc3..440c197ef1e 100644 --- a/buffer/buffer.ts +++ b/buffer/buffer.ts @@ -1,6 +1,11 @@ namespace $ { export class $mol_buffer extends DataView { + static from< This extends typeof $mol_buffer >( this: This, array: string | Uint8Array ) { + if( typeof array === 'string' ) array = $mol_base64_ae_decode( array ) + return new this( array.buffer, array.byteOffset, array.byteLength ) as InstanceType< This > + } + static toString() { return $$.$mol_func_name( this ) } @@ -91,5 +96,9 @@ namespace $ { return new Uint8Array( this.buffer, this.byteOffset, this.byteLength ) } + toString() { + return $mol_base64_ae_encode( this.asArray() ) + } + } }