index.js
function readEntry(buf) {
  let off = 0

  let type = buf.readUInt8(off)

  off += 1

  let [key, keySize] = readStr(buf.slice(off))

  off += keySize

  switch (type) {
    case 0x00: // Nested entries
      let [kvs, kvsSize] = readEntries(buf.slice(off))

      return [key, kvs, off + kvsSize]

    case 0x01: // String
      let [str, strSize] = readStr(buf.slice(off))

      return [key, str, off + strSize]

    case 0x02: // Int
      return [key, buf.readUInt32LE(off), off + 4]

    default:
      throw new Error(`Unhandled entry type: ${type}`)
  }
}
function readEntry(buf) {
  let off = 0

  let type = buf.readUInt8(off)

  off += 1

  let [key, keySize] = readStr(buf.slice(off))

  off += keySize

  switch (type) {
    case 0x00: // Nested entries
      let [kvs, kvsSize] = readEntries(buf.slice(off))

      return [key, kvs, off + kvsSize]

    case 0x01: // String
      let [str, strSize] = readStr(buf.slice(off))

      return [key, str, off + strSize]

    case 0x02: // Int
      return [key, buf.readUInt32LE(off), off + 4]

    default:
      throw new Error(`Unhandled entry type: ${type}`)
  }
}
function readEntry ( buf ) { let off = 0 let type = buf . readUInt8 ( off ) off += 1 let [ key , keySize ] = readStr ( buf . slice ( off ) ) off += keySize switch ( type ) { case 0x00 : // Nested entries let [ kvs , kvsSize ] = readEntries ( buf . slice ( off ) ) return [ key , kvs , off + kvsSize ] case 0x01 : // String let [ str , strSize ] = readStr ( buf . slice ( off ) ) return [ key , str , off + strSize ] case 0x02 : // Int return [ key , buf . readUInt32LE ( off ) , off + 4 ] default : throw new Error ( ` ${ type } ` ) } }
Read a single entry, returning the key-value pair and bytes read
Read a single entry returning the key - value pair and bytes read