Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xan105/node-vdf
Valve VDF Key/Value format parser (text and binary)
https://github.com/xan105/node-vdf
binary key node steam value valve vdf
Last synced: about 2 months ago
JSON representation
Valve VDF Key/Value format parser (text and binary)
- Host: GitHub
- URL: https://github.com/xan105/node-vdf
- Owner: xan105
- License: mit
- Created: 2023-09-20T16:40:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-25T10:03:46.000Z (about 1 year ago)
- Last Synced: 2024-09-19T12:23:18.062Z (4 months ago)
- Topics: binary, key, node, steam, value, valve, vdf
- Language: JavaScript
- Homepage:
- Size: 1.38 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
About
=====Valve VDF Key/Value format parser (text and binary).
This format can be found in Steam protobuffer message and in the Steam Client files as well as some Source Engine stuff.
📦 Scoped `@xan105` packages are for my own personal use but feel free to use them.
Example
=======Reading binary VDF .bin file
```js
import { parse } from "@xan105/vdf/binary";
import { readFile } from "node:fs/promises";const filePath = "C:\\Program Files (x86)\\Steam\\appcache\\stats\\UserGameStatsSchema_218620.bin";
const buffer = await readFile(filePath);
const vdf = parse(buffer);
```Reading text VDF file
```js
import { parse } from "@xan105/vdf";
import { readFile } from "node:fs/promises";const filePath = "C:\\Program Files (x86)\\Steam\\appcache\\localization.vdf";
const string = await readFile(filePath, "utf8");
const vdf = parse(string);
```Install
=======```
npm install @xan105/vdf
```API
===⚠️ This module is only available as an ECMAScript module (ESM).
## Named export
#### `parse(string: string, option?: object): object`
Decode the VDF key/value text formatted string into an object.
⚙️ Options
- translate?: boolean | object
translate option accepts the following object for granular control or a boolean which force all options to true/false:
|name|type|default|description|
|----|----|-------|-----------|
|bool|boolean|true|String to boolean|
|number|boolean|false|String to number or [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)|
|unsafe|boolean|false|Set to true to keep unsafe integer instead of bigint|❌ Throws on error
Example:
```js
import { parse } from "@xan105/vdf";
import { readFile } from "node:fs/promises";const filePath = "steam_input_for_ps4_controller.vdf";
const string = await readFile(filePath, "utf8");const vdf = parse(string, { translate: {
bool: true,
number: true,
unsafe: false
}});//All values will be string
const vdf = parse(string, { translate: false });
```⚠️ JSON compatibility
Some integers will be represented as **BigInt** due to their size if the related translate options are used.
**BigInt is not a valid value in the JSON spec**.
As such when stringify-ing the returned object you'll need to handle the JSON stringify replacer function to prevent it to fail.A common workaround is to represent them as a string:
```js
JSON.stringify(data, function(key, value) {
if(typeof value === "bigint")
return value.toString();
else
return value;
});
```### `binary`
#### `parse(buffer: Buffer, offset?: number[]): object`
Decode the VDF key/value binary formatted buffer into an object (starting at the given offset if any).
_NB: offset is an array so it can be passed by reference_
❌ Throws on error
Example:
```js
import { parse } from "@xan105/vdf/binary";
import { readFile } from "node:fs/promises";const filePath = "C:\\Program Files (x86)\\Steam\\appcache\\stats\\UserGameStatsSchema_218620.bin";
const buffer = await readFile(filePath);
const vdf = parse(buffer);
```💡 Note that binary ".vdf" file usually requires additional processing like handling file header.
⚠️ JSON compatibility
Some numbers will be represented as **BigInt** due to their size ((u)int64).
**BigInt is not a valid value in the JSON spec**.
As such when stringify-ing the returned object you'll need to handle the JSON stringify replacer function to prevent it to fail.A common workaround is to represent them as a string:
```js
JSON.stringify(data, function(key, value) {
if(typeof value === "bigint")
return value.toString();
else
return value;
});
```