Socket
Book a DemoInstallSign in
Socket

varstruct-cstring

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

varstruct-cstring

Encode / decode C strings.

latest
Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
0
-100%
Maintainers
2
Weekly downloads
 
Created
Source

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

Keywords

varstruct

FAQs

Package last updated on 21 Nov 2022

Did you know?

Socket

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