@@ -23,7 +23,9 @@ const pool = raw.map((uint8) => {
2323 const hex = buffer . toString ( 'hex' )
2424 const shared = new Uint8Array ( new SharedArrayBuffer ( uint8 . length ) )
2525 shared . set ( uint8 )
26- return { uint8, shared, buffer, hex, base32, base32padded, base32hex, base32hexPadded }
26+ const ab = uint8 . buffer
27+ if ( ab . byteLength !== uint8 . byteLength ) throw new Error ( 'Unexpected pooled Uint8Array' )
28+ return { uint8, ab, shared, buffer, hex, base32, base32padded, base32hex, base32hexPadded }
2729} )
2830
2931describe ( 'toBase32' , ( ) => {
@@ -110,7 +112,7 @@ describe('fromBase32', () => {
110112 t . assert . throws ( ( ) => fromBase32hex ( input . toUpperCase ( ) ) )
111113 t . assert . throws ( ( ) => fromBase32 ( input . toLowerCase ( ) ) )
112114 t . assert . throws ( ( ) => fromBase32hex ( input . toLowerCase ( ) ) )
113- for ( const format of [ 'uint8' , 'buffer' , 'hex' ] ) {
115+ for ( const format of [ 'uint8' , 'buffer' , 'arraybuffer' , ' hex'] ) {
114116 t . assert . throws ( ( ) => fromBase32 ( input , { format } ) )
115117 t . assert . throws ( ( ) => fromBase32hex ( input , { format } ) )
116118 }
@@ -145,9 +147,18 @@ describe('fromBase32', () => {
145147 } )
146148
147149 test ( 'buffer' , ( t ) => {
148- for ( const { base32, base32hex, buffer } of pool ) {
150+ for ( const { base32, base32padded , base32hex, buffer } of pool ) {
149151 t . assert . deepStrictEqual ( fromBase32 ( base32 , { format : 'buffer' } ) , buffer )
152+ t . assert . deepStrictEqual ( fromBase32 ( base32padded , { format : 'buffer' } ) , buffer )
150153 t . assert . deepStrictEqual ( fromBase32hex ( base32hex , { format : 'buffer' } ) , buffer )
151154 }
152155 } )
156+
157+ test ( 'arraybuffer' , ( t ) => {
158+ for ( const { base32, base32padded, base32hex, ab } of pool ) {
159+ t . assert . deepStrictEqual ( fromBase32 ( base32 , { format : 'arraybuffer' } ) , ab )
160+ t . assert . deepStrictEqual ( fromBase32 ( base32padded , { format : 'arraybuffer' } ) , ab )
161+ t . assert . deepStrictEqual ( fromBase32hex ( base32hex , { format : 'arraybuffer' } ) , ab )
162+ }
163+ } )
153164} )
0 commit comments