Socket
Socket
Sign inDemoInstall

decode-ico

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decode-ico - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

fixtures/dino-0.png

13

index.js

@@ -150,4 +150,6 @@ function makeDivisibleByFour (input) {

if (input.readUInt16LE(2, true) !== 1) {
throw new Error('Invalid magic bytes')
const type = input.readUInt16LE(2, true)
if (type !== 1 && type !== 2) {
throw new Error('Invalid image type')
}

@@ -168,2 +170,7 @@

const hotspot = (type !== 2 ? null : {
x: input.readUInt16LE(6 + (16 * idx) + 4, true),
y: input.readUInt16LE(6 + (16 * idx) + 6, true)
})
if (isPng(input, offset)) {

@@ -173,2 +180,3 @@ return {

height,
hotspot,
type: 'png',

@@ -184,2 +192,3 @@ width

height: bmp.height,
hotspot,
type: 'bmp',

@@ -186,0 +195,0 @@ width: bmp.width

2

package.json
{
"name": "decode-ico",
"version": "0.1.3",
"version": "0.1.4",
"license": "MIT",

@@ -5,0 +5,0 @@ "repository": "LinusU/decode-ico",

@@ -21,6 +21,6 @@ # Decode ICO

console.log(images[0])
//=> { width: 16, height: 16, type: 'bmp', data: Buffer(...) }
//=> { width: 16, height: 16, type: 'bmp', data: Buffer(...), hotspot: null }
console.log(images[1])
//=> { width: 32, height: 32, type: 'bmp', data: Buffer(...) }
//=> { width: 32, height: 32, type: 'bmp', data: Buffer(...), hotspot: null }
```

@@ -40,5 +40,8 @@

- `data: Buffer` - The data of the image, format depends on `type`, see below
- `hotspot: null | Hotspot` - If the image is a cursor (`.cur`), this is the hotspot
The format of the `data` parameter depends on the type of image. When the image is of type `bmp`, the `data` buffer will hold raw pixel data in the RGBA order, with integer values between 0 and 255 (included). When the type is `png`, the buffer will be png data.
The `hotspot` property will either be `null`, or an object with an `x` and `y` property.
💡 The `png` data can be written to a file with the `.png` extension directly, or be decoded by [node-lodepng](https://github.com/LinusU/node-lodepng) which will give you the same raw format as the `bmp` type.

@@ -45,2 +45,3 @@ /* eslint-env mocha */

assert.strictEqual(actual.height, expected.height)
assert.strictEqual(actual.hotspot, null)

@@ -60,1 +61,27 @@ const imageData = (actual.type === 'png')

}
describe('Decoding of dino.cur', () => {
let result
it('decodes the source', () => {
result = decodeIco(fs.readFileSync('fixtures/dino.cur'))
})
it(`extracts image #0`, () => {
const actual = result[0]
return loadPng('fixtures/dino-0.png').then((expected) => {
assert.strictEqual(actual.width, expected.width)
assert.strictEqual(actual.height, expected.height)
assert.deepStrictEqual(actual.hotspot, { x: 1, y: 2 })
const imageData = (actual.type === 'png')
? lodepng.decode(actual.data)
: Promise.resolve(actual)
return imageData.then((imageData) => {
assert.strictEqual(imageData.data.length, expected.data.length, 'The decoded data should match the target data (length)')
assert.ok(Buffer.compare(imageData.data, expected.data) === 0, 'The decoded data should match the target data (bytes)')
})
})
})
})
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