BlyxDocumentation
Browse chapters
Documentation / Workflow recipes

Kinglet · Serve a byte range at end of file

Plan a full or single-range HTTP response against a known representation size.

Serve a byte range at end of file

An inclusive last byte becomes a read length with a plus one. Handle suffixes, empty resources and unsatisfied offsets explicitly. A request for bytes 90 through 200 of a 100-byte resource returns ten bytes beginning at 90.

Run the framework with your own input

Install Blyx 0.2.1 and a Rust toolchain with a host linker, then run the versioned project. Each positional argument is a number or a comma-separated numerical vector. The CLI accepts up to 16 entries per vector. The imported module accepts longer inputs.

git clone --depth 1 --branch v0.1.0 https://github.com/Rahulchaube1/blyx-kinglet.git
cd blyx-kinglet
blyxc native-run project.blyx -- 100 1 90 200

API and return values

Returns [status, body offset, body length, full length]. Mode 0 sends the full body, 1 uses first/last, 2 uses first as a suffix count. Header parsing and multipart ranges belong to the host. Invalid input returns an empty vector.

ArgumentAccepted input
sizenonnegative exact integer
modenonnegative exact integer
firstnonnegative exact integer
lastexact signed integer

Use the libraries independently

The framework vendors the same library source published in these two repositories. Each module has its own package page, input contract and regression suite.

Try the program

Output Ready
Expected output
206
90
10
100
Open in the full playground →

Practice

Change mode = 2.0, first = 12.0, last = -1.0. Predict the result, then run the program.

Hint

Returns [status, body offset, body length, full length]. Mode 0 sends the full body, 1 uses first/last, 2 uses first as a suffix count. Header parsing and multipart ranges belong to the host.

Worked solution

The result vector is [206, 88, 12, 100]. Compare its fields with the return layout in the API section.

Find

    let mode = 1.0;

Replace with

    let mode = 2.0;

Find

    let first = 90.0;

Replace with

    let first = 12.0;

Find

    let last = 200.0;

Replace with

    let last = -1.0;

Output after the change

206
88
12
100