Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

varstruct-cstring

exodusmovement14MIT2.0.1

Encode / decode C strings.

varstruct, cstring, c string, c, string

readme

varstruct-cstring

npm Build Status JavaScript standard style

Easily encode / decode strings as C strings, that is, null-terminated \0. This is useful to retain compatibility with data structures written in other languages.

Install

npm i --save varstruct #must install varstruct first
npm i --save varstruct-cstring

Example

const vstruct = require('varstruct')
const cstring = require('varstruct-cstring')

const strings = vstruct([
  { name: 'first', type: cstring(16) },
  { name: 'last', type: cstring(16) }
])

const data = {
  first: 'Satoshi',
  last: 'Nakamoto'
}

const buffer = strings.encode(data)
console.log(buffer.toString('hex')) // => '5361746f7368690000000000000000004e616b616d6f746f0000000000000000'

const decodedData = strings.decode(buffer)
console.dir(decodedData) // => { first: 'Satoshi', last: 'Nakamoto' }

License

MIT Copyright Exodus Movement, Inc. 2016

changelog

2.0.1 / 2022-11-21

  • Fix package.json URLs

2.0.0 / 2022-11-21

  • Requires Node.js v14+
  • Flow source code not included in npm package (#17)

1.0.2 / 2017-05-19

  • Remove runtime type checks

1.0.1 / 2016-10-19

  • code tidy [#1]

1.0.0 / 2016-10-17

  • initial release