File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -220,6 +220,12 @@ The expected error should be [subclassed by the `internal/errors` module](https:
220
220
221
221
Tests whether ` name ` and ` expected ` are part of a raised warning.
222
222
223
+ ## getArrayBufferViews(buf)
224
+ * ` buf ` [ < ; Buffer>] ( https://nodejs.org/api/buffer.html#buffer_class_buffer )
225
+ * return [ < ; ArrayBufferView[ ;] ; >] ( https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView )
226
+
227
+ Returns an instance of all possible ` ArrayBufferView ` s of the provided Buffer.
228
+
223
229
### hasCrypto
224
230
* return [ < ; Boolean>] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type )
225
231
Original file line number Diff line number Diff line change @@ -654,3 +654,29 @@ exports.skipIfInspectorDisabled = function skipIfInspectorDisabled() {
654
654
process . exit ( 0 ) ;
655
655
}
656
656
} ;
657
+
658
+ const arrayBufferViews = [
659
+ Int8Array ,
660
+ Uint8Array ,
661
+ Uint8ClampedArray ,
662
+ Int16Array ,
663
+ Uint16Array ,
664
+ Int32Array ,
665
+ Uint32Array ,
666
+ Float32Array ,
667
+ Float64Array ,
668
+ DataView
669
+ ] ;
670
+
671
+ exports . getArrayBufferViews = function getArrayBufferViews ( buf ) {
672
+ const { buffer, byteOffset, byteLength } = buf ;
673
+
674
+ const out = [ ] ;
675
+ for ( const type of arrayBufferViews ) {
676
+ const { BYTES_PER_ELEMENT = 1 } = type ;
677
+ if ( byteLength % BYTES_PER_ELEMENT === 0 ) {
678
+ out . push ( new type ( buffer , byteOffset , byteLength / BYTES_PER_ELEMENT ) ) ;
679
+ }
680
+ }
681
+ return out ;
682
+ } ;
You can’t perform that action at this time.
0 commit comments