@@ -8,7 +8,8 @@ const Binary = require('../driver').get().Binary;
8
8
const utils = require ( '../utils' ) ;
9
9
const Buffer = require ( 'safe-buffer' ) . Buffer ;
10
10
11
- const NodeBuffer = global . Buffer || Buffer ;
11
+ // Yes this is weird. See https://github.com/feross/safe-buffer/pull/23
12
+ const proto = Buffer . from ( '' ) . constructor . prototype ;
12
13
13
14
/**
14
15
* Mongoose Buffer constructor.
@@ -134,7 +135,7 @@ MongooseBuffer.mixin = {
134
135
*/
135
136
136
137
write : function ( ) {
137
- const written = NodeBuffer . prototype . write . apply ( this , arguments ) ;
138
+ const written = proto . write . apply ( this , arguments ) ;
138
139
139
140
if ( written > 0 ) {
140
141
this . _markModified ( ) ;
@@ -157,7 +158,7 @@ MongooseBuffer.mixin = {
157
158
*/
158
159
159
160
copy : function ( target ) {
160
- const ret = NodeBuffer . prototype . copy . apply ( this , arguments ) ;
161
+ const ret = proto . copy . apply ( this , arguments ) ;
161
162
162
163
if ( target && target . isMongooseBuffer ) {
163
164
target . _markModified ( ) ;
@@ -181,11 +182,11 @@ MongooseBuffer.mixin = {
181
182
'writeUInt16LE writeUInt16BE writeUInt32LE writeUInt32BE ' +
182
183
'writeInt16LE writeInt16BE writeInt32LE writeInt32BE ' + 'writeFloatLE writeFloatBE writeDoubleLE writeDoubleBE' )
183
184
) . split ( ' ' ) . forEach ( function ( method ) {
184
- if ( ! NodeBuffer . prototype [ method ] ) {
185
+ if ( ! proto [ method ] ) {
185
186
return ;
186
187
}
187
188
MongooseBuffer . mixin [ method ] = function ( ) {
188
- const ret = NodeBuffer . prototype [ method ] . apply ( this , arguments ) ;
189
+ const ret = proto [ method ] . apply ( this , arguments ) ;
189
190
this . _markModified ( ) ;
190
191
return ret ;
191
192
} ;
0 commit comments