npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ipp-encoder

v5.0.0

Published

Internet Printing Protocol (IPP) encoder and decoder

Downloads

13,263

Readme

ipp-encoder

Internet Printing Protocol (IPP) encoder and decoder.

This module can be used to implement either a printing client or a printer server.

Build status js-standard-style abstract-encoding

Installation

npm install ipp-encoder

Usage

Printer server example:

var ipp = require('ipp-encoder')
var C = ipp.CONSTANTS

// decode binary buffer from IPP client
var decoded = ipp.request.decode(buf)

// ...handle request...

// prepare response
var response = {
  statusCode: C.SUCCESSFUL_OK, // set `operationId` instead if encoding a request
  requestId: decoded.requestId,
  groups: [
    { tag: C.OPERATION_ATTRIBUTES_TAG, attributes: [
      { tag: C.CHARSET, name: 'attributes-charset', value: 'utf-8' },
      { tag: C.NATURAL_LANG, name: 'attributes-natural-language', value: 'en-us' },
      { tag: C.TEXT_WITH_LANG, name: 'status-message', value: { lang: 'en-us', value: 'successful-ok' } }
    ] },
    { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
      { tag: C.INTEGER, name: 'job-id', value: 147 },
      { tag: C.NAME_WITH_LANG, name: 'job-name', value: { lang: 'en-us', value: 'Foobar' } }
    ] }
  ]
}

// encode response to binary buffer
ipp.response.encode(response) // <Buffer 01 01 00 00 ... >

API

ipp.CONSTANTS

An object containing IPP constants. See constants.js for the complete list.

ipp.STATUS_CODES

Map of IPP status codes to descriptive strings. See status-codes.js for the complete list.

ipp.request.decode(buffer[, start][, end])

Decode an IPP request buffer and returns the request object.

Options:

  • buffer - The buffer containing the request
  • start - An optional start-offset from where to start parsing the request (defaults to 0)
  • end - An optional end-offset specifying at which byte to end the decoding (defaults to buffer.length)

Request object structure:

{
  version: {
    major: 1,
    minor: 1
  },
  operationId: 0x02,
  requestId: 1,
  groups: [
    { tag: C.OPERATION_ATTRIBUTES_TAG, attributes: [
      { tag: 0x47, name: 'attributes-charset', value: ['utf-8'] },
      { tag: 0x48, name: 'attributes-natural-language', value: ['en-us'] },
      { tag: 0x45, name: 'printer-uri', value: ['ipp://watson.local.:3000/'] },
      { tag: 0x42, name: 'job-name', value: ['foobar'] },
      { tag: 0x22, name: 'ipp-attribute-fidelity', value: [true] }
    ] },
    { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
      { tag: 0x21, name: 'copies', value: [20] },
      { tag: 0x44, name: 'sides', value: ['two-sided-long-edge'] }
    ] }
  ]
}

After decoding ipp.request.decode.bytes is set to the amount of bytes used to decode the object.

Note that any data after the IPP headers are ignored.

ipp.request.encode(obj[, buffer][, offset])

Encode an IPP request object and returns en encoded buffer.

Options:

  • obj - The object containing the request
  • buffer - An optional buffer in which to write the encoded request
  • offset - An optional offset from where to start writing the encoded data in the buffer (defaults to 0)

Response object structure:

{
  statusCode: 0x00,
  requestId: 1,
  groups: [
    { tag: C.OPERATION_ATTRIBUTES_TAG, attributes: [
      { tag: 0x47, name: 'attributes-charset', value: ['utf-8'] },
      { tag: 0x48, name: 'attributes-natural-language', value: ['en-us'] },
      { tag: 0x41, name: 'status-message', value: ['successful-ok'] }
    ] },
    { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
      { tag: 0x21, name: 'job-id', value: [147] },
      { tag: 0x45, name: 'job-uri', value: ['ipp://watosn.local.:3000/123'] }
      { tag: 0x44, name: 'job-state', value: ['pending'] }
    ] }
  ]
}

It's possible to provide a custom IPP version in the same format is seen in the request. Default IPP version is 1.1.

After encoding, ipp.request.encode.bytes is set to the amount of bytes used to encode the object.

ipp.request.encodingLength(obj)

Returns the number of bytes it would take to encode the given IPP request object.

ipp.response.decode(buffer[, start][, end])

Same as ipp.request.decode(), but for IPP responses.

After decoding ipp.response.decode.bytes is set to the amount of bytes used to decode the object.

ipp.response.encode(obj[, buffer][, offset])

Same as ipp.request.encode(), but for IPP responses.

After encoding, ipp.response.encode.bytes is set to the amount of bytes used to encode the object.

ipp.response.encodingLength(obj)

Same as ipp.request.encodingLength(), but for IPP responses.

License

MIT