1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
22 var SlowBuffer = process.binding('buffer').SlowBuffer;
23 var assert = require('assert');
25 exports.INSPECT_MAX_BYTES = 50;
29 if (n < 16) return '0' + n.toString(16);
30 return n.toString(16);
34 SlowBuffer.prototype.inspect = function() {
37 for (var i = 0; i < len; i++) {
38 out[i] = toHex(this[i]);
39 if (i == exports.INSPECT_MAX_BYTES) {
44 return '<SlowBuffer ' + out.join(' ') + '>';
48 SlowBuffer.prototype.hexSlice = function(start, end) {
49 var len = this.length;
51 if (!start || start < 0) start = 0;
52 if (!end || end < 0 || end > len) end = len;
55 for (var i = start; i < end; i++) {
56 out += toHex(this[i]);
63 SlowBuffer.prototype.toString = function(encoding, start, end) {
64 encoding = String(encoding || 'utf8').toLowerCase();
66 if (typeof end == 'undefined') end = this.length;
68 // Fastpath empty strings
75 return this.hexSlice(start, end);
79 return this.utf8Slice(start, end);
82 return this.asciiSlice(start, end);
85 return this.binarySlice(start, end);
88 return this.base64Slice(start, end);
92 return this.ucs2Slice(start, end);
95 throw new Error('Unknown encoding');
100 SlowBuffer.prototype.hexWrite = function(string, offset, length) {
101 offset = +offset || 0;
102 var remaining = this.length - offset;
107 if (length > remaining) {
112 // must be an even number of digits
113 var strLen = string.length;
115 throw new Error('Invalid hex string');
117 if (length > strLen / 2) {
120 for (var i = 0; i < length; i++) {
121 var byte = parseInt(string.substr(i * 2, 2), 16);
122 if (isNaN(byte)) throw new Error('Invalid hex string');
123 this[offset + i] = byte;
125 SlowBuffer._charsWritten = i * 2;
130 SlowBuffer.prototype.write = function(string, offset, length, encoding) {
131 // Support both (string, offset, length, encoding)
132 // and the legacy (string, encoding, offset, length)
133 if (isFinite(offset)) {
134 if (!isFinite(length)) {
145 offset = +offset || 0;
146 var remaining = this.length - offset;
151 if (length > remaining) {
155 encoding = String(encoding || 'utf8').toLowerCase();
159 return this.hexWrite(string, offset, length);
163 return this.utf8Write(string, offset, length);
166 return this.asciiWrite(string, offset, length);
169 return this.binaryWrite(string, offset, length);
172 return this.base64Write(string, offset, length);
176 return this.ucs2Write(string, offset, length);
179 throw new Error('Unknown encoding');
185 SlowBuffer.prototype.slice = function(start, end) {
186 if (end === undefined) end = this.length;
188 if (end > this.length) {
189 throw new Error('oob');
192 throw new Error('oob');
195 return new Buffer(this, end - start, +start);
199 function coerce(length) {
200 // Coerce length to a number (possibly NaN), round up
201 // in case it's fractional (e.g. 123.456) then do a
202 // double negate to coerce a NaN to 0. Easy, right?
203 length = ~~Math.ceil(+length);
204 return length < 0 ? 0 : length;
210 function Buffer(subject, encoding, offset) {
211 if (!(this instanceof Buffer)) {
212 return new Buffer(subject, encoding, offset);
218 if (typeof offset === 'number') {
219 this.length = coerce(encoding);
220 this.parent = subject;
221 this.offset = offset;
224 switch (type = typeof subject) {
226 this.length = coerce(subject);
230 this.length = Buffer.byteLength(subject, encoding);
233 case 'object': // Assume object is an array
234 this.length = coerce(subject.length);
238 throw new Error('First argument needs to be a number, ' +
242 if (this.length > Buffer.poolSize) {
243 // Big buffer, just alloc one.
244 this.parent = new SlowBuffer(this.length);
249 if (!pool || pool.length - pool.used < this.length) allocPool();
251 this.offset = pool.used;
252 pool.used += this.length;
255 // Treat array-ish objects as a byte array.
256 if (isArrayIsh(subject)) {
257 for (var i = 0; i < this.length; i++) {
258 this.parent[i + this.offset] = subject[i];
260 } else if (type == 'string') {
262 this.length = this.write(subject, 0, encoding);
266 SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length);
269 function isArrayIsh(subject) {
270 return Array.isArray(subject) || Buffer.isBuffer(subject) ||
271 subject && typeof subject === 'object' &&
272 typeof subject.length === 'number';
275 exports.SlowBuffer = SlowBuffer;
276 exports.Buffer = Buffer;
278 Buffer.poolSize = 8 * 1024;
281 function allocPool() {
282 pool = new SlowBuffer(Buffer.poolSize);
288 Buffer.isBuffer = function isBuffer(b) {
289 return b instanceof Buffer || b instanceof SlowBuffer;
294 Buffer.prototype.inspect = function inspect() {
298 for (var i = 0; i < len; i++) {
299 out[i] = toHex(this.parent[i + this.offset]);
300 if (i == exports.INSPECT_MAX_BYTES) {
306 return '<Buffer ' + out.join(' ') + '>';
310 Buffer.prototype.get = function get(i) {
311 if (i < 0 || i >= this.length) throw new Error('oob');
312 return this.parent[this.offset + i];
316 Buffer.prototype.set = function set(i, v) {
317 if (i < 0 || i >= this.length) throw new Error('oob');
318 return this.parent[this.offset + i] = v;
322 // write(string, offset = 0, length = buffer.length-offset, encoding = 'utf8')
323 Buffer.prototype.write = function(string, offset, length, encoding) {
324 // Support both (string, offset, length, encoding)
325 // and the legacy (string, encoding, offset, length)
326 if (isFinite(offset)) {
327 if (!isFinite(length)) {
338 offset = +offset || 0;
339 var remaining = this.length - offset;
344 if (length > remaining) {
348 encoding = String(encoding || 'utf8').toLowerCase();
353 ret = this.parent.hexWrite(string, this.offset + offset, length);
358 ret = this.parent.utf8Write(string, this.offset + offset, length);
362 ret = this.parent.asciiWrite(string, this.offset + offset, length);
366 ret = this.parent.binaryWrite(string, this.offset + offset, length);
370 // Warning: maxLength not taken into account in base64Write
371 ret = this.parent.base64Write(string, this.offset + offset, length);
376 ret = this.parent.ucs2Write(string, this.offset + offset, length);
380 throw new Error('Unknown encoding');
383 Buffer._charsWritten = SlowBuffer._charsWritten;
389 // toString(encoding, start=0, end=buffer.length)
390 Buffer.prototype.toString = function(encoding, start, end) {
391 encoding = String(encoding || 'utf8').toLowerCase();
393 if (typeof start == 'undefined' || start < 0) {
395 } else if (start > this.length) {
399 if (typeof end == 'undefined' || end > this.length) {
401 } else if (end < 0) {
405 start = start + this.offset;
406 end = end + this.offset;
410 return this.parent.hexSlice(start, end);
414 return this.parent.utf8Slice(start, end);
417 return this.parent.asciiSlice(start, end);
420 return this.parent.binarySlice(start, end);
423 return this.parent.base64Slice(start, end);
427 return this.parent.ucs2Slice(start, end);
430 throw new Error('Unknown encoding');
436 Buffer.byteLength = SlowBuffer.byteLength;
439 // fill(value, start=0, end=buffer.length)
440 Buffer.prototype.fill = function fill(value, start, end) {
441 value || (value = 0);
442 start || (start = 0);
443 end || (end = this.length);
445 if (typeof value === 'string') {
446 value = value.charCodeAt(0);
448 if (!(typeof value === 'number') || isNaN(value)) {
449 throw new Error('value is not a number');
452 if (end < start) throw new Error('end < start');
454 // Fill 0 bytes; we're done
455 if (end === start) return 0;
456 if (this.length == 0) return 0;
458 if (start < 0 || start >= this.length) {
459 throw new Error('start out of bounds');
462 if (end < 0 || end > this.length) {
463 throw new Error('end out of bounds');
466 return this.parent.fill(value,
472 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
473 Buffer.prototype.copy = function(target, target_start, start, end) {
475 start || (start = 0);
476 end || (end = this.length);
477 target_start || (target_start = 0);
479 if (end < start) throw new Error('sourceEnd < sourceStart');
481 // Copy 0 bytes; we're done
482 if (end === start) return 0;
483 if (target.length == 0 || source.length == 0) return 0;
485 if (target_start < 0 || target_start >= target.length) {
486 throw new Error('targetStart out of bounds');
489 if (start < 0 || start >= source.length) {
490 throw new Error('sourceStart out of bounds');
493 if (end < 0 || end > source.length) {
494 throw new Error('sourceEnd out of bounds');
498 if (end > this.length) {
502 if (target.length - target_start < end - start) {
503 end = target.length - target_start + start;
506 return this.parent.copy(target.parent,
507 target_start + target.offset,
514 Buffer.prototype.slice = function(start, end) {
515 if (end === undefined) end = this.length;
516 if (end > this.length) throw new Error('oob');
517 if (start > end) throw new Error('oob');
519 return new Buffer(this.parent, end - start, +start + this.offset);
523 // Legacy methods for backwards compatibility.
525 Buffer.prototype.utf8Slice = function(start, end) {
526 return this.toString('utf8', start, end);
529 Buffer.prototype.binarySlice = function(start, end) {
530 return this.toString('binary', start, end);
533 Buffer.prototype.asciiSlice = function(start, end) {
534 return this.toString('ascii', start, end);
537 Buffer.prototype.utf8Write = function(string, offset) {
538 return this.write(string, offset, 'utf8');
541 Buffer.prototype.binaryWrite = function(string, offset) {
542 return this.write(string, offset, 'binary');
545 Buffer.prototype.asciiWrite = function(string, offset) {
546 return this.write(string, offset, 'ascii');
549 Buffer.prototype.readUInt8 = function(offset, noAssert) {
553 assert.ok(offset !== undefined && offset !== null,
556 assert.ok(offset < buffer.length,
557 'Trying to read beyond buffer length');
560 return buffer[offset];
563 function readUInt16(buffer, offset, isBigEndian, noAssert) {
568 assert.ok(typeof (isBigEndian) === 'boolean',
569 'missing or invalid endian');
571 assert.ok(offset !== undefined && offset !== null,
574 assert.ok(offset + 1 < buffer.length,
575 'Trying to read beyond buffer length');
579 val = buffer[offset] << 8;
580 val |= buffer[offset + 1];
582 val = buffer[offset];
583 val |= buffer[offset + 1] << 8;
589 Buffer.prototype.readUInt16LE = function(offset, noAssert) {
590 return readUInt16(this, offset, false, noAssert);
593 Buffer.prototype.readUInt16BE = function(offset, noAssert) {
594 return readUInt16(this, offset, true, noAssert);
597 function readUInt32(buffer, offset, isBigEndian, noAssert) {
601 assert.ok(typeof (isBigEndian) === 'boolean',
602 'missing or invalid endian');
604 assert.ok(offset !== undefined && offset !== null,
607 assert.ok(offset + 3 < buffer.length,
608 'Trying to read beyond buffer length');
612 val = buffer[offset + 1] << 16;
613 val |= buffer[offset + 2] << 8;
614 val |= buffer[offset + 3];
615 val = val + (buffer[offset] << 24 >>> 0);
617 val = buffer[offset + 2] << 16;
618 val |= buffer[offset + 1] << 8;
619 val |= buffer[offset];
620 val = val + (buffer[offset + 3] << 24 >>> 0);
626 Buffer.prototype.readUInt32LE = function(offset, noAssert) {
627 return readUInt32(this, offset, false, noAssert);
630 Buffer.prototype.readUInt32BE = function(offset, noAssert) {
631 return readUInt32(this, offset, true, noAssert);
636 * Signed integer types, yay team! A reminder on how two's complement actually
637 * works. The first bit is the signed bit, i.e. tells us whether or not the
638 * number should be positive or negative. If the two's complement value is
639 * positive, then we're done, as it's equivalent to the unsigned representation.
641 * Now if the number is positive, you're pretty much done, you can just leverage
642 * the unsigned translations and return those. Unfortunately, negative numbers
643 * aren't quite that straightforward.
645 * At first glance, one might be inclined to use the traditional formula to
646 * translate binary numbers between the positive and negative values in two's
647 * complement. (Though it doesn't quite work for the most negative value)
649 * - invert all the bits
650 * - add one to the result
652 * Of course, this doesn't quite work in Javascript. Take for example the value
653 * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of
654 * course, Javascript will do the following:
659 * Whoh there, Javascript, that's not quite right. But wait, according to
660 * Javascript that's perfectly correct. When Javascript ends up seeing the
661 * constant 0xff80, it has no notion that it is actually a signed number. It
662 * assumes that we've input the unsigned value 0xff80. Thus, when it does the
663 * binary negation, it casts it into a signed value, (positive 0xff80). Then
664 * when you perform binary negation on that, it turns it into a negative number.
666 * Instead, we're going to have to use the following general formula, that works
667 * in a rather Javascript friendly way. I'm glad we don't support this kind of
668 * weird numbering scheme in the kernel.
670 * (BIT-MAX - (unsigned)val + 1) * -1
672 * The astute observer, may think that this doesn't make sense for 8-bit numbers
673 * (really it isn't necessary for them). However, when you get 16-bit numbers,
674 * you do. Let's go back to our prior example and see how this will look:
676 * (0xffff - 0xff80 + 1) * -1
680 Buffer.prototype.readInt8 = function(offset, noAssert) {
685 assert.ok(offset !== undefined && offset !== null,
688 assert.ok(offset < buffer.length,
689 'Trying to read beyond buffer length');
692 neg = buffer[offset] & 0x80;
694 return (buffer[offset]);
697 return ((0xff - buffer[offset] + 1) * -1);
700 function readInt16(buffer, offset, isBigEndian, noAssert) {
704 assert.ok(typeof (isBigEndian) === 'boolean',
705 'missing or invalid endian');
707 assert.ok(offset !== undefined && offset !== null,
710 assert.ok(offset + 1 < buffer.length,
711 'Trying to read beyond buffer length');
714 val = readUInt16(buffer, offset, isBigEndian, noAssert);
720 return (0xffff - val + 1) * -1;
723 Buffer.prototype.readInt16LE = function(offset, noAssert) {
724 return readInt16(this, offset, false, noAssert);
727 Buffer.prototype.readInt16BE = function(offset, noAssert) {
728 return readInt16(this, offset, true, noAssert);
731 function readInt32(buffer, offset, isBigEndian, noAssert) {
735 assert.ok(typeof (isBigEndian) === 'boolean',
736 'missing or invalid endian');
738 assert.ok(offset !== undefined && offset !== null,
741 assert.ok(offset + 3 < buffer.length,
742 'Trying to read beyond buffer length');
745 val = readUInt32(buffer, offset, isBigEndian, noAssert);
746 neg = val & 0x80000000;
751 return (0xffffffff - val + 1) * -1;
754 Buffer.prototype.readInt32LE = function(offset, noAssert) {
755 return readInt32(this, offset, false, noAssert);
758 Buffer.prototype.readInt32BE = function(offset, noAssert) {
759 return readInt32(this, offset, true, noAssert);
762 function readFloat(buffer, offset, isBigEndian, noAssert) {
764 assert.ok(typeof (isBigEndian) === 'boolean',
765 'missing or invalid endian');
767 assert.ok(offset + 3 < buffer.length,
768 'Trying to read beyond buffer length');
771 return require('buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
775 Buffer.prototype.readFloatLE = function(offset, noAssert) {
776 return readFloat(this, offset, false, noAssert);
779 Buffer.prototype.readFloatBE = function(offset, noAssert) {
780 return readFloat(this, offset, true, noAssert);
783 function readDouble(buffer, offset, isBigEndian, noAssert) {
785 assert.ok(typeof (isBigEndian) === 'boolean',
786 'missing or invalid endian');
788 assert.ok(offset + 7 < buffer.length,
789 'Trying to read beyond buffer length');
792 return require('buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
796 Buffer.prototype.readDoubleLE = function(offset, noAssert) {
797 return readDouble(this, offset, false, noAssert);
800 Buffer.prototype.readDoubleBE = function(offset, noAssert) {
801 return readDouble(this, offset, true, noAssert);
806 * We have to make sure that the value is a valid integer. This means that it is
807 * non-negative. It has no fractional component and that it does not exceed the
808 * maximum allowed value.
810 * value The number to check for validity
812 * max The maximum value
814 function verifuint(value, max) {
815 assert.ok(typeof (value) == 'number',
816 'cannot write a non-number as a number');
818 assert.ok(value >= 0,
819 'specified a negative value for writing an unsigned value');
821 assert.ok(value <= max, 'value is larger than maximum value for type');
823 assert.ok(Math.floor(value) === value, 'value has a fractional component');
826 Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
830 assert.ok(value !== undefined && value !== null,
833 assert.ok(offset !== undefined && offset !== null,
836 assert.ok(offset < buffer.length,
837 'trying to write beyond buffer length');
839 verifuint(value, 0xff);
842 buffer[offset] = value;
845 function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
847 assert.ok(value !== undefined && value !== null,
850 assert.ok(typeof (isBigEndian) === 'boolean',
851 'missing or invalid endian');
853 assert.ok(offset !== undefined && offset !== null,
856 assert.ok(offset + 1 < buffer.length,
857 'trying to write beyond buffer length');
859 verifuint(value, 0xffff);
863 buffer[offset] = (value & 0xff00) >>> 8;
864 buffer[offset + 1] = value & 0x00ff;
866 buffer[offset + 1] = (value & 0xff00) >>> 8;
867 buffer[offset] = value & 0x00ff;
871 Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
872 writeUInt16(this, value, offset, false, noAssert);
875 Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
876 writeUInt16(this, value, offset, true, noAssert);
879 function writeUInt32(buffer, value, offset, isBigEndian, noAssert) {
881 assert.ok(value !== undefined && value !== null,
884 assert.ok(typeof (isBigEndian) === 'boolean',
885 'missing or invalid endian');
887 assert.ok(offset !== undefined && offset !== null,
890 assert.ok(offset + 3 < buffer.length,
891 'trying to write beyond buffer length');
893 verifuint(value, 0xffffffff);
897 buffer[offset] = (value >>> 24) & 0xff;
898 buffer[offset + 1] = (value >>> 16) & 0xff;
899 buffer[offset + 2] = (value >>> 8) & 0xff;
900 buffer[offset + 3] = value & 0xff;
902 buffer[offset + 3] = (value >>> 24) & 0xff;
903 buffer[offset + 2] = (value >>> 16) & 0xff;
904 buffer[offset + 1] = (value >>> 8) & 0xff;
905 buffer[offset] = value & 0xff;
909 Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
910 writeUInt32(this, value, offset, false, noAssert);
913 Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
914 writeUInt32(this, value, offset, true, noAssert);
919 * We now move onto our friends in the signed number category. Unlike unsigned
920 * numbers, we're going to have to worry a bit more about how we put values into
921 * arrays. Since we are only worrying about signed 32-bit values, we're in
922 * slightly better shape. Unfortunately, we really can't do our favorite binary
923 * & in this system. It really seems to do the wrong thing. For example:
928 * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
929 * this aren't treated as a signed number. Ultimately a bad thing.
931 * What we're going to want to do is basically create the unsigned equivalent of
932 * our representation and pass that off to the wuint* functions. To do that
933 * we're going to do the following:
935 * - if the value is positive
936 * we can pass it directly off to the equivalent wuint
937 * - if the value is negative
938 * we do the following computation:
939 * mb + val + 1, where
940 * mb is the maximum unsigned value in that byte size
941 * val is the Javascript negative integer
944 * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
945 * you do out the computations:
951 * You can then encode this value as the signed version. This is really rather
952 * hacky, but it should work and get the job done which is our goal here.
956 * A series of checks to make sure we actually have a signed 32-bit number
958 function verifsint(value, max, min) {
959 assert.ok(typeof (value) == 'number',
960 'cannot write a non-number as a number');
962 assert.ok(value <= max, 'value larger than maximum allowed value');
964 assert.ok(value >= min, 'value smaller than minimum allowed value');
966 assert.ok(Math.floor(value) === value, 'value has a fractional component');
969 function verifIEEE754(value, max, min) {
970 assert.ok(typeof (value) == 'number',
971 'cannot write a non-number as a number');
973 assert.ok(value <= max, 'value larger than maximum allowed value');
975 assert.ok(value >= min, 'value smaller than minimum allowed value');
978 Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
982 assert.ok(value !== undefined && value !== null,
985 assert.ok(offset !== undefined && offset !== null,
988 assert.ok(offset < buffer.length,
989 'Trying to write beyond buffer length');
991 verifsint(value, 0x7f, -0x80);
995 buffer.writeUInt8(value, offset, noAssert);
997 buffer.writeUInt8(0xff + value + 1, offset, noAssert);
1001 function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
1003 assert.ok(value !== undefined && value !== null,
1006 assert.ok(typeof (isBigEndian) === 'boolean',
1007 'missing or invalid endian');
1009 assert.ok(offset !== undefined && offset !== null,
1012 assert.ok(offset + 1 < buffer.length,
1013 'Trying to write beyond buffer length');
1015 verifsint(value, 0x7fff, -0x8000);
1019 writeUInt16(buffer, value, offset, isBigEndian, noAssert);
1021 writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
1025 Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
1026 writeInt16(this, value, offset, false, noAssert);
1029 Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
1030 writeInt16(this, value, offset, true, noAssert);
1033 function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
1035 assert.ok(value !== undefined && value !== null,
1038 assert.ok(typeof (isBigEndian) === 'boolean',
1039 'missing or invalid endian');
1041 assert.ok(offset !== undefined && offset !== null,
1044 assert.ok(offset + 3 < buffer.length,
1045 'Trying to write beyond buffer length');
1047 verifsint(value, 0x7fffffff, -0x80000000);
1051 writeUInt32(buffer, value, offset, isBigEndian, noAssert);
1053 writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
1057 Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
1058 writeInt32(this, value, offset, false, noAssert);
1061 Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
1062 writeInt32(this, value, offset, true, noAssert);
1065 function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
1067 assert.ok(value !== undefined && value !== null,
1070 assert.ok(typeof (isBigEndian) === 'boolean',
1071 'missing or invalid endian');
1073 assert.ok(offset !== undefined && offset !== null,
1076 assert.ok(offset + 3 < buffer.length,
1077 'Trying to write beyond buffer length');
1079 verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
1082 require('buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
1086 Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
1087 writeFloat(this, value, offset, false, noAssert);
1090 Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
1091 writeFloat(this, value, offset, true, noAssert);
1094 function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
1096 assert.ok(value !== undefined && value !== null,
1099 assert.ok(typeof (isBigEndian) === 'boolean',
1100 'missing or invalid endian');
1102 assert.ok(offset !== undefined && offset !== null,
1105 assert.ok(offset + 7 < buffer.length,
1106 'Trying to write beyond buffer length');
1108 verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
1111 require('buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
1115 Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
1116 writeDouble(this, value, offset, false, noAssert);
1119 Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
1120 writeDouble(this, value, offset, true, noAssert);