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

Package detail

valve-key-values-binary

80LK27MIT1.0.1TypeScript support: included

A simple parser of the KeyValues binary format from Valve

keyvalues, key-values, keyvaluesbinary, key-valuesbinary, keyvalues-binary, key-values-binary, valve, vdf, steam, binary

readme

valve-key-values-binary

A simple parser of the KeyValues binary format (or Binary VDF) from Valve

Usage

Parsing

VKVB.parse returned parsed Map from your file

import VKVB, { Map } from "./index.js";

type ShortcutsRoot = {
    shortcuts: Shortcut[];
}
type Shortcut = {
    appid: number;
    AppName: string;
}

const buffer = readFileSync('path/to/file');
const root:Map<ShortcutsRoot> = VKVB.parse<ShortcutsRoot>(buffer);

console.log("OUTPUT:\n", root.toJSON());

Serializate

VKVB.serializate takes as an argument the Map object returned by the VKVB.parse

// root from Usage -> Parsing
const buffer = VKVB.serializate(root);
writeFileSync('path/to/file', buffer);

How to parse and serializate specific files, such as AppInfo and PackageInfo

AppInfo and PackageInfo are supported by default. To work with other specific files, you can extend the Parser and Serializer classes provided in the package.

Examples:

Work with Map

To get and set the data in the Map, use the get[Type](key: string) and set[Type](key: string, value: T) methods

Supported data types: (Type -> T)

  • Int -> number
    const myValue: number = root.getInt('my_key');
    root.setInt('my_key', 1);
  • Ptr -> number
    const myValue: number = root.getPtr('my_key');
    root.setInt('my_key', 1);
  • UInt64 -> bigint
    const myValue: bigint = root.getUInt64('my_key');
    root.setUInt64('my_key', 1n);
  • String -> string
    const myValue: string = root.getString('my_key');
    root.setString('my_key', 'my string');
  • WString -> string
    const myValue: string = root.getWString('my_key');
    root.setWString('my_key', 'my string');
  • Map -> Map
    const myValue: Map = root.getMap('my_key');
    const myMap = new Map<T>();
    // ...
    root.setMap('my_key', myMap);

Another methods

  • delete(key:string) remove key from map
  • getKeys() return all setted keys in map
  • getKeysWithType() return Record<Keys, VKVB.TYPE>
  • getKeysWithSType() return Record<Keys, string>, where string is name type
  • getKeyType(key: string) return VKVB.TYPE by key or null if key not exsist
  • getKeySType(key: string) return name type by key or null if key not exsist
  • toJSON() return simple object.

[WARNING] bigint cannot be converted to a JSON value. You may need to define BigInt.prototype.toJSON.