Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-binary-schema-parser

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-binary-schema-parser - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

0

example/index.js

@@ -0,0 +0,0 @@ import fs from 'fs'

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

2

package.json
{
"name": "js-binary-schema-parser",
"version": "2.0.0",
"version": "2.0.1",
"description": "Parse binary files with a schema into nicely readable objects",

@@ -5,0 +5,0 @@ "dependencies": {},

@@ -13,3 +13,3 @@ # js Binary Schema Parser

npm install --save js-binary-schema-parser
npm install js-binary-schema-parser

@@ -19,3 +19,3 @@ _Create a schema and parse a file:_

import { parse, conditional } from 'js-binary-schema-parser'
import { buildStream, readByte } from 'js-binary-schema-parser/parsers/uint8'
import { buildStream, readByte } from 'js-binary-schema-parser/lib/parsers/uint8'

@@ -36,3 +36,3 @@ const schema = [

import GIF from 'js-binary-schema-parser/schemas/gif'
import GIF from 'js-binary-schema-parser/lib/schemas/gif'

@@ -39,0 +39,0 @@ Schemas are an array of _parts_, which are objects containing a single key label, and the parser to use at that point in time. This format was chosen to ensure parse ordering was consistent. _Parts_ can also contain other parts internally, and include syntax for loops, and conditionals. You can also include your own custom functions for parsing, providing direct access to the given data stream. Below is an example of a schema using the `Uint8TypedArray` parser provided to parse the GIF format header. You can also see a full example [here][2] of parsing entire GIF files.

@@ -0,0 +0,0 @@ export const parse = (stream, schema, result = {}, parent = result) => {

@@ -0,0 +0,0 @@ // Default stream and parsers for Uint8TypedArray data type

@@ -10,3 +10,3 @@ import { conditional, loop } from '../'

readArray,
readBits
readBits,
} from '../parsers/uint8'

@@ -16,5 +16,6 @@

var subBlocksSchema = {
blocks: stream => {
blocks: (stream) => {
const terminator = 0x00
const chunks = []
const streamSize = stream.data.length
var total = 0

@@ -26,2 +27,9 @@ for (

) {
// catch corrupted files with no terminator
if (stream.pos + size >= streamSize) {
const availableSize = streamSize - stream.pos
chunks.push(readBytes(availableSize)(stream))
total += availableSize
break
}
chunks.push(readBytes(size)(stream))

@@ -37,3 +45,3 @@ total += size

return result
}
},
}

@@ -52,11 +60,11 @@

userInput: { index: 6 },
transparentColorGiven: { index: 7 }
})
transparentColorGiven: { index: 7 },
}),
},
{ delay: readUnsigned(true) },
{ transparentColorIndex: readByte() },
{ terminator: readByte() }
]
{ terminator: readByte() },
],
},
stream => {
(stream) => {
var codes = peekBytes(2)(stream)

@@ -84,6 +92,6 @@ return codes[0] === 0x21 && codes[1] === 0xf9

future: { index: 3, length: 2 },
size: { index: 5, length: 3 }
})
}
]
size: { index: 5, length: 3 },
}),
},
],
},

@@ -94,3 +102,3 @@ conditional(

return Math.pow(2, parent.descriptor.lct.size + 1)
})
}),
},

@@ -101,6 +109,6 @@ (stream, result, parent) => {

),
{ data: [{ minCodeSize: readByte() }, subBlocksSchema] }
]
{ data: [{ minCodeSize: readByte() }, subBlocksSchema] },
],
},
stream => {
(stream) => {
return peekByte()(stream) === 0x2c

@@ -118,8 +126,8 @@ }

preData: (stream, result, parent) =>
readBytes(parent.text.blockSize)(stream)
readBytes(parent.text.blockSize)(stream),
},
subBlocksSchema
]
subBlocksSchema,
],
},
stream => {
(stream) => {
var codes = peekBytes(2)(stream)

@@ -137,6 +145,6 @@ return codes[0] === 0x21 && codes[1] === 0x01

{ id: (stream, result, parent) => readString(parent.blockSize)(stream) },
subBlocksSchema
]
subBlocksSchema,
],
},
stream => {
(stream) => {
var codes = peekBytes(2)(stream)

@@ -150,5 +158,5 @@ return codes[0] === 0x21 && codes[1] === 0xff

{
comment: [{ codes: readBytes(2) }, subBlocksSchema]
comment: [{ codes: readBytes(2) }, subBlocksSchema],
},
stream => {
(stream) => {
var codes = peekBytes(2)(stream)

@@ -170,8 +178,8 @@ return codes[0] === 0x21 && codes[1] === 0xfe

sort: { index: 4 },
size: { index: 5, length: 3 }
})
size: { index: 5, length: 3 },
}),
},
{ backgroundColorIndex: readByte() },
{ pixelAspectRatio: readByte() }
]
{ pixelAspectRatio: readByte() },
],
},

@@ -182,3 +190,3 @@ conditional(

Math.pow(2, result.lsd.gct.size + 1)
)
),
},

@@ -191,3 +199,3 @@ (stream, result) => result.lsd.gct.exists

[gceSchema, applicationSchema, commentSchema, imageSchema, textSchema],
stream => {
(stream) => {
var nextCode = peekByte()(stream)

@@ -200,6 +208,6 @@ // rather than check for a terminator, we should check for the existence

}
)
}
),
},
]
export default schema

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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