Appearance
@bendyline/molen-pack/node
Molen content packs: build, open and read zip packs of models and documents from any source.
ts
import { /* … */ } from '@bendyline/molen-pack/node';Interfaces
BuiltPackFile
Properties
file
ts
file: string;File name, <id>-<first 12 hex of the file's sha256>.zip.
fileSha256
ts
fileSha256: string;sha256 of the file's bytes.
indexPath
ts
indexPath: string;Path of the updated index.json.
manifest
ts
manifest: PackManifest;path
ts
path: string;Absolute path of the written file.
size
ts
size: number;PackSource
Properties
config
ts
config: PackSourceConfig;dir
ts
dir: string;files
ts
files: PackFile[];Variables
PACK_INDEX_FILE
ts
const PACK_INDEX_FILE: "index.json" = "index.json";Index written next to built packs.
PACK_SOURCE_FILE
ts
const PACK_SOURCE_FILE: "molen-pack.source.json" = "molen-pack.source.json";Build settings file in a pack's source directory.
Functions
buildPack()
ts
function buildPack(dir, options): Promise<BuiltPackFile>;Build a pack source directory into outDir. The file name carries a hash of its bytes, so a host can cache it forever; index.json in outDir maps the pack id to its current file, and the previous build of the same pack is removed.
Parameters
dir
string
options
compression?
"auto" | "store"
outDir
string
solid?
boolean
Returns
Promise<BuiltPackFile>
extractPack()
ts
function extractPack(pack, outDir): Promise<string[]>;Write every file of a pack into outDir, with a molen-pack.source.json that builds it back to the same content.
Parameters
pack
outDir
string
Returns
Promise<string[]>
listPackSource()
ts
function listPackSource(dir): Promise<{
config: PackSourceConfig;
dir: string;
paths: string[];
}>;List validated source settings and included paths without loading file contents.
Parameters
dir
string
Returns
Promise<{ config: PackSourceConfig; dir: string; paths: string[]; }>
openDirPack()
ts
function openDirPack(dir, options?): Promise<Pack>;Open an unbuilt pack source directory as a pack. It has the manifest the built pack would have (same entries, ids and contentHash), without zipping anything.
Parameters
dir
string
options?
Pick<OpenPackOptions, "expect">
Returns
Promise<Pack>
openFilePack()
ts
function openFilePack(path, options?): Promise<Pack>;Open a built pack file. Reads go to the file on demand; close() releases it.
Parameters
path
string
options?
Returns
Promise<Pack>
openPackAt()
ts
function openPackAt(source, options?): Promise<Pack>;Open a pack from a URL, a built pack file, or a pack source directory.
Parameters
source
string
options?
Returns
Promise<Pack>
readPackSource()
ts
function readPackSource(dir): Promise<PackSource>;Read a pack's source directory: its settings file and every file it includes.
Parameters
dir
string
Returns
Promise<PackSource>
recordInPackIndex()
ts
function recordInPackIndex(
outDir,
id,
entry
): Promise<string>;List a pack file in outDir/index.json (a molen/pack-index@1 document), replacing the entry for the same pack id and deleting that entry's previous file when nothing else lists it. Returns the index path. A browser opens packs from that index (openPacksFromIndex in molen-earth).
Parameters
outDir
string
id
string
entry
Returns
Promise<string>