Skip to content

Commit

Permalink
Merge pull request #12160 from hasezoey/changeSplitToEach
Browse files Browse the repository at this point in the history
style(buffer): change ".split" to "utils.each" for defining methods
  • Loading branch information
Uzlopak committed Jul 27, 2022
2 parents 7dfe820 + 769aa21 commit 46b629b
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions lib/types/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,26 @@ MongooseBuffer.mixin = {
* Compile other Buffer methods marking this buffer as modified.
*/

(
// node < 0.5
('writeUInt8 writeUInt16 writeUInt32 writeInt8 writeInt16 writeInt32 ' +
'writeFloat writeDouble fill ' +
'utf8Write binaryWrite asciiWrite set ' +

// node >= 0.5
'writeUInt16LE writeUInt16BE writeUInt32LE writeUInt32BE ' +
'writeInt16LE writeInt16BE writeInt32LE writeInt32BE ' + 'writeFloatLE writeFloatBE writeDoubleLE writeDoubleBE')
).split(' ').forEach(function(method) {
if (!Buffer.prototype[method]) {
return;
}
MongooseBuffer.mixin[method] = function() {
const ret = Buffer.prototype[method].apply(this, arguments);
this._markModified();
return ret;
};
});
utils.each(
[
// node < 0.5
'writeUInt8', 'writeUInt16', 'writeUInt32', 'writeInt8', 'writeInt16', 'writeInt32',
'writeFloat', 'writeDouble', 'fill',
'utf8Write', 'binaryWrite', 'asciiWrite', 'set',

// node >= 0.5
'writeUInt16LE', 'writeUInt16BE', 'writeUInt32LE', 'writeUInt32BE',
'writeInt16LE', 'writeInt16BE', 'writeInt32LE', 'writeInt32BE', 'writeFloatLE', 'writeFloatBE', 'writeDoubleLE', 'writeDoubleBE']
, function(method) {
if (!Buffer.prototype[method]) {
return;
}
MongooseBuffer.mixin[method] = function() {
const ret = Buffer.prototype[method].apply(this, arguments);
this._markModified();
return ret;
};
});

/**
* Converts this buffer to its Binary type representation.
Expand Down

0 comments on commit 46b629b

Please sign in to comment.