Skip to content

Commit 232cc74

Browse files
committed
Add pobb.in live fetch example to rust crate & document publishing and usage
1 parent d93e1fe commit 232cc74

5 files changed

Lines changed: 256 additions & 1 deletion

File tree

js/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# pob-parser
2+
3+
A high-performance, robust, and zero-dependency library for parsing, encoding, decoding, and fetching Path of Building (PoB) import codes and pobb.in links. Available in both TypeScript/JavaScript (npm) and Rust (crates.io).
4+
5+
## Features
6+
7+
- Zero external dependencies (JS/TS version) using modern Web Streams.
8+
- High performance and safe encoding/decoding using base64 and zlib.
9+
- Link parsing and retrieval: Resolves standard and user-profile URLs for pobb.in to fetch the raw import codes.
10+
- Idiomatic Rust version with conditional async/blocking fetching using features.
11+
- Local playground demo: A minimal, terminal-inspired web application included in the repository to test, edit, and re-encode builds.
12+
13+
## Installation
14+
15+
### TypeScript / JavaScript (npm)
16+
17+
```bash
18+
npm install pob-parser
19+
```
20+
21+
### Rust (crates.io)
22+
23+
Add to your Cargo.toml:
24+
```toml
25+
[dependencies]
26+
pob-parser = "1.0.0"
27+
```
28+
29+
To enable HTTP fetching (async/blocking):
30+
```toml
31+
pob-parser = { version = "1.0.0", features = ["fetch", "blocking"] }
32+
```
33+
34+
## Quick Start Examples
35+
36+
### TypeScript / JavaScript
37+
38+
```typescript
39+
import { encode, decode, parseUrl, fetchRawCode, fetchAndDecode } from 'pob-parser';
40+
41+
// 1. Decode a PoB code to XML
42+
const pobCode = "eJzLSM3JyVcozy/KSQEAGgsEXQ=="; // "hello world" compressed
43+
const xml = await decode(pobCode);
44+
console.log(xml); // "hello world"
45+
46+
// 2. Encode XML to PoB Code
47+
const newPobCode = await encode(xml);
48+
console.log(newPobCode); // "eJzLSM3JyVcozy_KSQEAGgsEXQ" (URL-safe, no padding)
49+
50+
// 3. Parse a pobb.in URL
51+
const parsed = parseUrl("https://pobb.in/eQVFNoqVZrza");
52+
console.log(parsed);
53+
// { id: 'eQVFNoqVZrza', rawUrl: 'https://pobb.in/eQVFNoqVZrza/raw' }
54+
55+
// 4. Fetch and decode from pobb.in
56+
const fetchedXml = await fetchAndDecode("https://pobb.in/eQVFNoqVZrza");
57+
console.log(fetchedXml);
58+
```
59+
60+
### Rust
61+
62+
```rust
63+
use pob_parser::{decode, encode, parse_url};
64+
65+
fn main() -> Result<(), pob_parser::Error> {
66+
// 1. Decode PoB code
67+
let xml = decode("eJzLSM3JyVcozy/KSQEAGgsEXQ==")?;
68+
println!("{}", xml); // "hello world"
69+
70+
// 2. Encode XML
71+
let encoded = encode(&xml)?;
72+
println!("{}", encoded); // "eJzLSM3JyVcozy_KSQEAGgsEXQ"
73+
74+
// 3. Parse pobb.in link
75+
let parsed = parse_url("https://pobb.in/eQVFNoqVZrza").unwrap();
76+
println!("Raw URL: {}", parsed.raw_url);
77+
78+
Ok(())
79+
}
80+
81+
// 4. Fetch and decode (requires the "fetch" feature)
82+
#[cfg(feature = "fetch")]
83+
async fn fetch_example() -> Result<(), pob_parser::Error> {
84+
let xml = pob_parser::fetch_and_decode("https://pobb.in/eQVFNoqVZrza", None).await?;
85+
println!("{}", xml);
86+
Ok(())
87+
}
88+
```
89+
90+
## Local Playground
91+
92+
### Run Locally with CORS Proxy
93+
94+
Since browsers block cross-origin requests (CORS) when executing client-side fetches directly to pobb.in, a local dev server with a built-in proxy is provided for testing:
95+
96+
1. Build the library bundles:
97+
```bash
98+
cd js
99+
npm run build
100+
```
101+
2. Start the dev server:
102+
```bash
103+
npm start
104+
```
105+
3. Open http://localhost:3000 in your browser to access the playground.
106+
107+
## Credits
108+
109+
- [PathOfBuildingAPI](https://github.com/ppoelzl/PathOfBuildingAPI) by ppoelzl
110+
- [pasteofexile](https://github.com/Dav1dde/pasteofexile) by Dav1dde

js/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pob-parser",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Path of Building (PoB) import code and pobb.in URL parser",
55
"repository": {
66
"type": "git",
@@ -10,6 +10,10 @@
1010
"url": "https://github.com/juddisjudd/pobpaser/issues"
1111
},
1212
"homepage": "https://juddisjudd.github.io/pobpaser/",
13+
"files": [
14+
"dist",
15+
"src"
16+
],
1317
"main": "./dist/index.cjs",
1418
"module": "./dist/index.js",
1519
"types": "./dist/index.d.ts",

rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = "MIT"
77
repository = "https://github.com/juddisjudd/pobpaser"
88
homepage = "https://juddisjudd.github.io/pobpaser/"
99
documentation = "https://docs.rs/pob-parser"
10+
readme = "README.md"
1011

1112
[dependencies]
1213
base64 = "0.22"

rust/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# pob-parser
2+
3+
A high-performance, robust, and zero-dependency library for parsing, encoding, decoding, and fetching Path of Building (PoB) import codes and pobb.in links. Available in both TypeScript/JavaScript (npm) and Rust (crates.io).
4+
5+
## Features
6+
7+
- Zero external dependencies (JS/TS version) using modern Web Streams.
8+
- High performance and safe encoding/decoding using base64 and zlib.
9+
- Link parsing and retrieval: Resolves standard and user-profile URLs for pobb.in to fetch the raw import codes.
10+
- Idiomatic Rust version with conditional async/blocking fetching using features.
11+
- Local playground demo: A minimal, terminal-inspired web application included in the repository to test, edit, and re-encode builds.
12+
13+
## Installation
14+
15+
### TypeScript / JavaScript (npm)
16+
17+
```bash
18+
npm install pob-parser
19+
```
20+
21+
### Rust (crates.io)
22+
23+
Add to your Cargo.toml:
24+
```toml
25+
[dependencies]
26+
pob-parser = "1.0.0"
27+
```
28+
29+
To enable HTTP fetching (async/blocking):
30+
```toml
31+
pob-parser = { version = "1.0.0", features = ["fetch", "blocking"] }
32+
```
33+
34+
## Quick Start Examples
35+
36+
### TypeScript / JavaScript
37+
38+
```typescript
39+
import { encode, decode, parseUrl, fetchRawCode, fetchAndDecode } from 'pob-parser';
40+
41+
// 1. Decode a PoB code to XML
42+
const pobCode = "eJzLSM3JyVcozy/KSQEAGgsEXQ=="; // "hello world" compressed
43+
const xml = await decode(pobCode);
44+
console.log(xml); // "hello world"
45+
46+
// 2. Encode XML to PoB Code
47+
const newPobCode = await encode(xml);
48+
console.log(newPobCode); // "eJzLSM3JyVcozy_KSQEAGgsEXQ" (URL-safe, no padding)
49+
50+
// 3. Parse a pobb.in URL
51+
const parsed = parseUrl("https://pobb.in/eQVFNoqVZrza");
52+
console.log(parsed);
53+
// { id: 'eQVFNoqVZrza', rawUrl: 'https://pobb.in/eQVFNoqVZrza/raw' }
54+
55+
// 4. Fetch and decode from pobb.in
56+
const fetchedXml = await fetchAndDecode("https://pobb.in/eQVFNoqVZrza");
57+
console.log(fetchedXml);
58+
```
59+
60+
### Rust
61+
62+
```rust
63+
use pob_parser::{decode, encode, parse_url};
64+
65+
fn main() -> Result<(), pob_parser::Error> {
66+
// 1. Decode PoB code
67+
let xml = decode("eJzLSM3JyVcozy/KSQEAGgsEXQ==")?;
68+
println!("{}", xml); // "hello world"
69+
70+
// 2. Encode XML
71+
let encoded = encode(&xml)?;
72+
println!("{}", encoded); // "eJzLSM3JyVcozy_KSQEAGgsEXQ"
73+
74+
// 3. Parse pobb.in link
75+
let parsed = parse_url("https://pobb.in/eQVFNoqVZrza").unwrap();
76+
println!("Raw URL: {}", parsed.raw_url);
77+
78+
Ok(())
79+
}
80+
81+
// 4. Fetch and decode (requires the "fetch" feature)
82+
#[cfg(feature = "fetch")]
83+
async fn fetch_example() -> Result<(), pob_parser::Error> {
84+
let xml = pob_parser::fetch_and_decode("https://pobb.in/eQVFNoqVZrza", None).await?;
85+
println!("{}", xml);
86+
Ok(())
87+
}
88+
```
89+
90+
## Local Playground
91+
92+
### Run Locally with CORS Proxy
93+
94+
Since browsers block cross-origin requests (CORS) when executing client-side fetches directly to pobb.in, a local dev server with a built-in proxy is provided for testing:
95+
96+
1. Build the library bundles:
97+
```bash
98+
cd js
99+
npm run build
100+
```
101+
2. Start the dev server:
102+
```bash
103+
npm start
104+
```
105+
3. Open http://localhost:3000 in your browser to access the playground.
106+
107+
## Credits
108+
109+
- [PathOfBuildingAPI](https://github.com/ppoelzl/PathOfBuildingAPI) by ppoelzl
110+
- [pasteofexile](https://github.com/Dav1dde/pasteofexile) by Dav1dde

rust/examples/fetch_pob.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#[cfg(feature = "blocking")]
2+
use pob_parser::fetch_and_decode_blocking;
3+
4+
#[cfg(feature = "blocking")]
5+
fn main() {
6+
let url = "https://pobb.in/E23x6r3rboyN";
7+
println!("Fetching and decoding PoB build from: {}", url);
8+
9+
match fetch_and_decode_blocking(url, None) {
10+
Ok(xml) => {
11+
println!("Success! Decoded XML length: {} characters", xml.len());
12+
println!("--- XML Snippet (First 500 chars) ---");
13+
let snippet: String = xml.chars().take(500).collect();
14+
println!("{}", snippet);
15+
println!("-------------------------------------");
16+
}
17+
Err(e) => {
18+
eprintln!("Error fetching and decoding build: {:?}", e);
19+
std::process::exit(1);
20+
}
21+
}
22+
}
23+
24+
#[cfg(not(feature = "blocking"))]
25+
fn main() {
26+
println!("The 'blocking' feature is not enabled.");
27+
println!("Please run this example with the blocking feature enabled:");
28+
println!("cargo run --example fetch_pob --features=\"blocking\"");
29+
}
30+

0 commit comments

Comments
 (0)