New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vox-reader

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vox-reader - npm Package Compare versions

Comparing version 2.0.3 to 2.1.0

index.d.ts

3

index.js

@@ -1,2 +0,3 @@

"use strict";
module.exports = require('./src/readVox');
//# sourceMappingURL=index.js.map
{
"name": "vox-reader",
"version": "2.0.3",
"version": "2.1.0",
"description": "Takes a Byte Array of .vox file data and returns a JavaScript Object with all the containing informations",

@@ -8,3 +8,4 @@ "main": "index.js",

"start": "node index.js",
"test": "node test/readVox.test.js"
"compile": "tsc",
"test": "tsc && ava"
},

@@ -16,6 +17,6 @@ "keywords": [

"file",
"reader"
"reader",
"loader"
],
"repository":
{
"repository": {
"type": "git",

@@ -26,3 +27,9 @@ "url": "https://github.com/florianfe/vox-reader.js.git"

"license": "MIT",
"dependencies": {}
"devDependencies": {
"@types/node": "^17.0.8",
"ava": "^4.0.1",
"json-diff": "^0.7.1",
"typescript": "^4.5.4",
"vox-saver": "^1.1.0"
}
}
# vox-reader
npm module for reading [.vox](https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt) files which can be exported in [MagickaVoxel](https://ephtracy.github.io/).
npm module for reading [.vox](https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt) files which can be exported in [MagickaVoxel](https://ephtracy.github.io/). It's the inverse function to [vox-saver.js](https://github.com/FlorianFe/vox-saver.js)

@@ -4,0 +4,0 @@ ## 💾 Installation

@@ -1,31 +0,23 @@

"use strict";
const read4ByteString = require('./shared/read4ByteString/read4ByteString');
const read4ByteInteger = require('./shared/read4ByteInteger/read4ByteInteger');
const groupArray = require('./shared/groupArray/groupArray');
const readRiffFile = require('./readRiffFile/readRiffFile');
const parseVoxChunk = require('./parseVoxChunk/parseVoxChunk');
const removeRiffStructure = require('./removeRiffStructure/removeRiffStructure');
const readVox = (buffer) =>
{
const BLOCK_SIZE = 4;
const OFFSET = 8; // VOX <space> 150 0 0 0
const data = [...buffer]; // convert buffer to array
const tokens = groupArray(data, BLOCK_SIZE);
const id = read4ByteString(tokens[0]);
const version = read4ByteInteger(tokens[1]);
if(id != 'VOX ') throw Error(`Id of .vox-file should be "VOX ", found "${id}".`);
if(version != 150) throw Error(`Version of .vox-file structure should be 150, found "${version}".`);
const riffData = readRiffFile(data, OFFSET, parseVoxChunk);
const result = removeRiffStructure(riffData);
return result;
}
const readVox = (buffer) => {
const BLOCK_SIZE = 4;
const OFFSET = 8; // VOX <space> 150 0 0 0
const data = [...buffer]; // convert buffer to array
const tokens = groupArray(data, BLOCK_SIZE);
const id = read4ByteString(tokens[0]);
const version = read4ByteInteger(tokens[1]);
if (id != 'VOX ')
throw Error(`Id of .vox-file should be "VOX ", found "${id}".`);
if (version != 150)
throw Error(`Version of .vox-file structure should be 150, found "${version}".`);
const riffData = readRiffFile(data, OFFSET, parseVoxChunk);
return removeRiffStructure(riffData);
};
module.exports = readVox;
//# sourceMappingURL=readVox.js.map

@@ -1,17 +0,14 @@

const groupArray = (array, groupSize) =>
{
return array.reduce((result, item, index) =>
{
const i1 = parseInt(index / groupSize);
const i2 = index % groupSize;
if(i2 == 0) result.push([]);
result[i1].push(item);
return result;
}, []);
}
"use strict";
const { floor } = Math;
const groupArray = (array, groupSize) => {
return array.reduce((result, item, index) => {
const i1 = floor(index / groupSize);
const i2 = index % groupSize;
if (i2 == 0)
result.push([]);
result[i1].push(item);
return result;
}, []);
};
module.exports = groupArray;
//# sourceMappingURL=groupArray.js.map

@@ -1,60 +0,35 @@

"use strict";
// see https://en.wikipedia.org/wiki/IEEE_754
const { floor } = Math;
const BYTE_SIZE = 8;
const flatten = (array) =>
[].concat.apply([], array);
const binarifyByte = (byte) =>
{
let bits = [];
for(let i=1; i <= BYTE_SIZE; i++)
{
const divident = 2 ** (BYTE_SIZE - i);
const bit = parseInt(byte / divident);
bits.push(bit);
byte = byte % divident;
}
return bits.reverse();
}
const getExponentValueOfBits = (bits) =>
bits.reduce((sum, bit, index) =>
(sum + ((bit) ? 2 ** (BYTE_SIZE - index - 1) : 0))
, -127);
const getMantissaValueOfBits = (bits, denormalized) =>
bits.reduce((sum, bit, index) =>
{
return sum + ((bit) ? 2 ** ((-1 * index) - 1) : 0)
}, (denormalized ? 0 : 1));
const read4ByteFloat = (data) =>
{
data = data.reverse();
const deepBits = data.map(byte => binarifyByte(byte).reverse());
const bits = flatten(deepBits);
const sign = bits[0];
let exponent = getExponentValueOfBits(bits.slice(1, 9));
const denormalized = (exponent === -127);
exponent += denormalized ? 1 : 0;
const mantissa = getMantissaValueOfBits(bits.slice(9), denormalized);
// potentes in JavaScript causes wrong result
if(mantissa === 0) return 0;
return ((sign) ? -1 : 1) * mantissa ** exponent;
}
const flatten = (array) => [].concat.apply([], array);
const binarifyByte = (byte) => {
let bits = [];
for (let i = 1; i <= BYTE_SIZE; i++) {
const divident = Math.pow(2, (BYTE_SIZE - i));
const bit = floor(byte / divident);
bits.push(bit);
byte = byte % divident;
}
return bits.reverse();
};
const getExponentValueOfBits = (bits) => bits.reduce((sum, bit, index) => (sum + ((bit) ? Math.pow(2, (BYTE_SIZE - index - 1)) : 0)), -127);
const getMantissaValueOfBits = (bits, denormalized) => bits.reduce((sum, bit, index) => {
return sum + ((bit) ? Math.pow(2, ((-1 * index) - 1)) : 0);
}, (denormalized ? 0 : 1));
const read4ByteFloat = (data) => {
data = data.reverse();
const deepBits = data.map(byte => binarifyByte(byte).reverse());
const bits = flatten(deepBits);
const sign = bits[0];
let exponent = getExponentValueOfBits(bits.slice(1, 9));
const denormalized = (exponent === -127);
exponent += denormalized ? 1 : 0;
const mantissa = getMantissaValueOfBits(bits.slice(9), denormalized);
// potentes in JavaScript causes wrong result
if (mantissa === 0)
return 0;
return ((sign) ? -1 : 1) * Math.pow(mantissa, exponent);
};
module.exports = read4ByteFloat;
//# sourceMappingURL=read4ByteFloat.js.map

@@ -1,5 +0,5 @@

const read4ByteInteger = (data) =>
data.map((num, index) => (num * 2 ** (8 * index)) )
.reduce((sum, summand) => sum + summand, 0);
"use strict";
const read4ByteInteger = (data) => data.map((num, index) => (num * Math.pow(2, (8 * index))))
.reduce((sum, summand) => sum + summand, 0);
module.exports = read4ByteInteger;
//# sourceMappingURL=read4ByteInteger.js.map

@@ -1,6 +0,5 @@

const read4ByteString = (data) =>
data.map(charCode => String.fromCharCode(charCode))
.join('');
"use strict";
const read4ByteString = (data) => data.map(charCode => String.fromCharCode(charCode))
.join('');
module.exports = read4ByteString;
//# sourceMappingURL=read4ByteString.js.map

@@ -1,11 +0,15 @@

"use strict";
const fs = require('fs');
const util = require('util');
const test = require('ava');
const readVox = require('../index');
fs.readFile('test/deer.vox', (error, buffer) =>
{
if (error) throw error;
console.log(util.inspect(readVox(buffer), false, null, true))
});
const writeVox = require('vox-saver');
const { diff } = require("json-diff");
test('test deer.vox', (t) => {
const buffer = fs.readFileSync('./test/deer.vox');
console.log(util.inspect(readVox(buffer), false, null, true));
const vox = readVox(buffer);
t.assert(diff(vox, readVox(writeVox(vox))) === undefined, "vox-reader and vox-writer should be the same");
t.pass();
});
//# sourceMappingURL=readVox.test.js.map
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc