Skip to content

Commit 1234307

Browse files
authored
Add custom Buffer polyfill for pre-ES2016 environments (stellar#118)
1 parent 80b7f29 commit 1234307

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

buffer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// See https://github.com/stellar/js-xdr/issues/117
2+
import { Buffer } from 'buffer';
3+
4+
if (!(Buffer.alloc(1).subarray(0, 1) instanceof Buffer)) {
5+
Buffer.prototype.subarray = function subarray(start, end) {
6+
const result = Uint8Array.prototype.subarray.call(this, start, end);
7+
Object.setPrototypeOf(result, Buffer.prototype);
8+
return result;
9+
};
10+
}
11+
12+
export default Buffer;

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = function () {
4747
};
4848
config.plugins.push(
4949
new webpack.ProvidePlugin({
50-
Buffer: ['buffer', 'Buffer']
50+
Buffer: [path.resolve(__dirname, 'buffer.js'), 'default']
5151
})
5252
);
5353
} else {

0 commit comments

Comments
 (0)