Skip to content

Commit

Permalink
$mol_buffer: from & to string
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Dec 2, 2023
1 parent d0fe347 commit d1227dd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions buffer/buffer.ts
Original file line number Diff line number Diff line change
@@ -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 )
}
Expand Down Expand Up @@ -91,5 +96,9 @@ namespace $ {
return new Uint8Array( this.buffer, this.byteOffset, this.byteLength )
}

toString() {
return $mol_base64_ae_encode( this.asArray() )
}

}
}

0 comments on commit d1227dd

Please sign in to comment.