Internationalization and localization tools


Locale-Sensitive JavaScript NodeJS Method

buf.readDoubleBE(offset[, noAssert]);
buf.readDoubleLE(offset[, noAssert]);
buf.readFloatBE(offset[, noAssert]);
buf.readFloatLE(offset[, noAssert]);
buf.readInt8(offset[, noAssert]);
buf.readInt16BE(offset[, noAssert]);
buf.readInt16LE(offset[, noAssert]);
buf.readInt32BE(offset[, noAssert]);
buf.readInt32LE(offset[, noAssert]);
buf.readIntBE(offset, byteLength[, noAssert]);
buf.readIntLE(offset, byteLength[, noAssert]);
buf.readUInt8(offset[, noAssert]);
buf.readUInt16BE(offset[, noAssert]);
buf.readUInt16LE(offset[, noAssert]);
buf.readUInt32BE(offset[, noAssert]);
buf.readUInt32LE(offset[, noAssert]);
buf.readUIntBE(offset, byteLength[, noAssert]);
buf.readUIntLE(offset, byteLength[, noAssert]);

buf.writeDoubleBE(value, offset[, noAssert]);
buf.writeDoubleLE(value, offset[, noAssert]);
buf.writeFloatBE(value, offset[, noAssert]);
buf.writeFloatLE(value, offset[, noAssert]);
buf.writeInt8(value, offset[, noAssert]);
buf.writeInt16BE(value, offset[, noAssert]);
buf.writeInt16LE(value, offset[, noAssert]);
buf.writeInt32BE(value, offset[, noAssert]);
buf.writeInt32LE(value, offset[, noAssert]);
buf.writeIntBE(value, offset, byteLength[, noAssert]);
buf.writeIntLE(value, offset, byteLength[, noAssert]);
buf.writeUInt8(value, offset[, noAssert]);
buf.writeUInt16BE(value, offset[, noAssert]);
buf.writeUInt16LE(value, offset[, noAssert]);
buf.writeUInt32BE(value, offset[, noAssert]);
buf.writeUInt32LE(value, offset[, noAssert]);
buf.writeUIntBE(value, offset, byteLength[, noAssert]);
buf.writeUIntLE(value, offset, byteLength[, noAssert]);

Internationalization (I18n) Method Overview

The buf.read methods read a Double, Float, Int or UInt of various sizes and either Little Endian or Big Endian format from the buffer.

The buf.write methods write a Double, Float, Int or UInt of various sizes and either Little Endian or Big Endian format to the Buffer.


For Example:
const buf = Buffer.from([1,2,3,4]);
buf.readFloatBE();
	// Returns: 2.387939260590663e-38
buf.readFloatLE();
	// Returns: 1.539989614439558e-36

const buf = Buffer.allocUnsafe(4);
buf.writeFloatBE(0xcafebabe, 0);
console.log(buf);
	// Prints: <Buffer 4f 4a fe bb>
buf.writeFloatLE(0xcafebabe, 0);
console.log(buf);
	// Prints: <Buffer bb fe 4a 4f>
				

Additional information regarding these methods is available here.

I18n Issues

The assumed endianness may be incorrect for the application.

Some unicode characters require more bytes to encode than others. Any offset given may not match if the buffer contains unicode characters.

Suggested Replacement

Double check to confirm that the appropriate endianness is used. If setting an offset on a buffer which may contain unicode characters, note that these characters may have variable byte lengths.

Globalyzer will detect this method and report it as an i18n issue. If you have determined that the call is being handled correctly, you can use Globalyzer's Ignore Comment functionality to ensure that it isn't picked up in a subsequent scan.



Locale-Sensitive JavaScript Methods

 

Lingoport internationalization and localization services and software