File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change 22
33var Buffer = require ( 'safe-buffer' ) . Buffer ;
44var isArray = require ( 'isarray' ) ;
5+ var typedArrayBuffer = require ( 'typed-array-buffer' ) ;
6+
7+ var isView = ArrayBuffer . isView || function isView ( obj ) {
8+ try {
9+ typedArrayBuffer ( obj ) ;
10+ return true ;
11+ } catch ( e ) {
12+ return false ;
13+ }
14+ } ;
515
616var useUint8Array = typeof Uint8Array !== 'undefined' ;
717var useArrayBuffer = typeof ArrayBuffer !== 'undefined'
8- && typeof Uint8Array !== 'undefined'
9- && ArrayBuffer . isView ;
18+ && typeof Uint8Array !== 'undefined' ;
1019var useFromArrayBuffer = useArrayBuffer && ( Buffer . prototype instanceof Uint8Array || Buffer . TYPED_ARRAY_SUPPORT ) ;
1120
1221module . exports = function toBuffer ( data , encoding ) {
@@ -26,7 +35,7 @@ module.exports = function toBuffer(data, encoding) {
2635 * Wrap any TypedArray instances and DataViews
2736 * Makes sense only on engines with full TypedArray support -- let Buffer detect that
2837 */
29- if ( useArrayBuffer && ArrayBuffer . isView ( data ) ) {
38+ if ( useArrayBuffer && isView ( data ) ) {
3039 // Bug in Node.js <6.3.1, which treats this as out-of-bounds
3140 if ( data . byteLength === 0 ) {
3241 return Buffer . alloc ( 0 ) ;
Original file line number Diff line number Diff line change 2626 "homepage" : " https://github.com/browserify/to-buffer" ,
2727 "dependencies" : {
2828 "isarray" : " ^2.0.5" ,
29- "safe-buffer" : " ^5.2.1"
29+ "safe-buffer" : " ^5.2.1" ,
30+ "typed-array-buffer" : " ^1.0.3"
3031 },
3132 "devDependencies" : {
3233 "@ljharb/eslint-config" : " ^21.1.1" ,
3738 "for-each" : " ^0.3.5" ,
3839 "npmignore" : " ^0.3.1" ,
3940 "nyc" : " ^10.3.2" ,
40- "tape" : " ^5.9.0" ,
41- "typed-array-buffer" : " ^1.0.3"
41+ "tape" : " ^5.9.0"
4242 },
4343 "engines" : {
4444 "node" : " >= 0.4"
You can’t perform that action at this time.
0 commit comments