Socket
Socket
Sign inDemoInstall

ico-endec

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ico-endec

ICO encoder and decoder library


Version published
Maintainers
1
Install size
25.6 kB
Created

Readme

Source

ICO encoder & decoder

This JavaScript library provides an encoder and decoder for ICO and CUR files. Although this library can encode and decode both BMP and PNG images, BMP endec does not provide bitmasking support, and as such, will not work with some icons. However, PNG support is widespread and has become a more defacto standard for application icons, so this problem is largely moot -- but it still would be nice to have.

Encoding

icoEndec.encode([Buffer||ArrayBuffer])

The encode function takes an array of ArrayBuffers or Buffers that contain BMP or PNG data. It returns a Buffer containing the binary data of the ICO file.

Example
const icoEndec   = require('ico-endec')
const fsPromises = require('fs').Promises

(async () => {
  let icoBuffer = icoEndec.encode([
    await fsPromises.readFile('myIcon-16x16.png'),
    await fsPromises.readFile('myIcon-32x32.png'),
    await fsPromises.readFile('myIcon-64x64.png')
  ])
  
  await fsPromises.writeFile('myIcon.ico', icoBuffer)
})()

Decoding

icoEndec.decode(Buffer)

The decode function takes a Buffer or an ArrayBuffer that holds the binary data of an ICO file. It returns an array of IconEntries.

Example
const icoEndec   = require('ico-endec')
const fsPromises = require('fs').Promises

(async () => {
  let icons = icoEndec.decode(await fsPromises.readFile('myIcon.ico'))
  
  icons.forEach((icon, index) => {
    fsPromises.writeFile(`myIcon-${icon.width}x${icon.height}.${icon.imageType}`, icon.imageData)
  })
})()

IconEntry

The IconEntry class stores various information about the given icon entry.

AccessorTypeDescription
widthNumberwidth of the image, maximum of 256
heightNumberheight of the image, maximum of 256
colorsNumbernumber of colors
colorPlanesNumbercolor planes of an ICO image
bitsPerPixelNumberbits per pixel of an ICO image
horizontalHotspotNumberhorizontal hotspot of a CUR image
verticalHotspotNumbervertical hotspot of a CUR image
imageSizeNumber(interal) size of imageData's buffer
imageOffsetNumber(interal) offset start of the image data
imageTypeString'png' or 'bmp'
imageDataBufferimage data of the icon

FAQs

Last updated on 12 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc