obj2gltf/lib/getBufferPadded.js

23 lines
596 B
JavaScript
Raw Normal View History

2021-08-02 11:31:59 -04:00
"use strict";
2017-07-19 17:56:24 -04:00
module.exports = getBufferPadded;
/**
* Pad the buffer to the next 4-byte boundary to ensure proper alignment for the section that follows.
*
* @param {Buffer} buffer The buffer.
* @returns {Buffer} The padded buffer.
*
* @private
*/
function getBufferPadded(buffer) {
2021-08-02 11:31:59 -04:00
const boundary = 4;
const byteLength = buffer.length;
const remainder = byteLength % boundary;
if (remainder === 0) {
return buffer;
}
const padding = remainder === 0 ? 0 : boundary - remainder;
const emptyBuffer = Buffer.alloc(padding);
return Buffer.concat([buffer, emptyBuffer]);
2017-07-19 17:56:24 -04:00
}