gui/webview/pack
The file format that holds an application's web files.
import gui.webview.pack
This is the file format behind the files of a webview application: a compressed and scrambled set of files, read from the end of an executable or from a file of its own. You rarely call it directly, because salam bundle does the packing and webview does the reading. Scrambling keeps names and contents out of sight; it is not encryption.
Pack a folder and read it back
PackDir compresses every file of a folder into one pack file and returns how many it stored, or -1. The key scrambles the content: it must be the same when you open the pack, and webview uses the application id. Open fills a Pack you declare first, Count says how many files it holds, and Read returns a Blob. A name that is not there gives a blob whose data is null, so test that before using it. The caller owns the bytes of a blob.
import gui.webview.pack
import os
import io
func main:
os.MkdirAll("www")
io.WriteFile("www/index.html", "<h1>Hello</h1>")
io.WriteFile("www/style.css", "body { margin: 0 }")
println "packed", pack.PackDir("www", "app.pack", "com.example.app"), "files"
mut opened := pack.Pack {}
if not pack.Open("app.pack", "com.example.app", opened):
println "could not open"
ret 1
end
println "holds", opened.Count()
page := opened.Read("index.html")
println "index.html is", page.size, "bytes"
missing := opened.Read("nothing.txt")
println "missing found:", missing.data != null
endPutting the pack inside a program
AppendPack adds a pack to the end of an executable, and Open accepts that executable as its path: it finds the pack at the end of the file. This is how a desktop program carries its pages in one file, and it is what salam bundle does for you. On macOS the pack goes into the application folder instead, so the signature of the program stays valid.
pack.PackDir("www", "app.pack", "com.example.app")
pack.AppendPack("notes", "app.pack")
Types
Blob
struct Blob| Name | Type | Description |
|---|---|---|
data | void* | A pointer to the bytes. |
size | i64 = 0 | The number of bytes. |
import gui.webview.pack
func main:
println pack.PackDir("www", "app.pack", "com.example.app")
println pack.AppendPack("app", "app.pack")
mut opened := pack.Pack {}
if pack.Open("app", "com.example.app", opened):
println opened.path, opened.key, opened.Count()
blob := opened.Read("index.html")
println blob.data != null, blob.size
end
println pack.ReadRange("app.pack", 0 as i64, 4 as i64) != null
endPack
struct Pack| Name | Type | Description |
|---|---|---|
path | str = "" | The file it was read from. |
key | str = "" | The key it was opened with. |
The example for this item is shown with the ones above: gui-webview-pack-Pack.salam
Count
func Count(): intThe example for this item is shown with the ones above: gui-webview-pack-Pack.salam
Read
func Read(name: str): Blobdata is null when it is not there.The example for this item is shown with the ones above: gui-webview-pack-Pack.salam
Functions
ReadRange
func ReadRange(path: str, offset: i64, n: i64): void*The example for this item is shown with the ones above: gui-webview-pack-Pack.salam
Open
func Open(path: str, key: str, out &: Pack): boolThe example for this item is shown with the ones above: gui-webview-pack-Pack.salam
PackDir
func PackDir(dir: str, out_path: str, key: str): intThe example for this item is shown with the ones above: gui-webview-pack-Pack.salam
AppendPack
func AppendPack(exe_path: str, pack_path: str): boolThe example for this item is shown with the ones above: gui-webview-pack-Pack.salam