Renamed files to ts

This commit is contained in:
junderw 2018-12-21 17:55:03 +09:00
parent 293116b20f
commit bb98289501
No known key found for this signature in database
GPG key ID: B256185D3A971908
44 changed files with 0 additions and 0 deletions

View file

@ -1,29 +0,0 @@
// https://github.com/feross/buffer/blob/master/index.js#L1127
function verifuint (value, max) {
if (typeof value !== 'number') throw new Error('cannot write a non-number as a number')
if (value < 0) throw new Error('specified a negative value for writing an unsigned value')
if (value > max) throw new Error('RangeError: value out of range')
if (Math.floor(value) !== value) throw new Error('value has a fractional component')
}
function readUInt64LE (buffer, offset) {
const a = buffer.readUInt32LE(offset)
let b = buffer.readUInt32LE(offset + 4)
b *= 0x100000000
verifuint(b + a, 0x001fffffffffffff)
return b + a
}
function writeUInt64LE (buffer, value, offset) {
verifuint(value, 0x001fffffffffffff)
buffer.writeInt32LE(value & -1, offset)
buffer.writeUInt32LE(Math.floor(value / 0x100000000), offset + 4)
return offset + 8
}
module.exports = {
readUInt64LE: readUInt64LE,
writeUInt64LE: writeUInt64LE
}