diff --git a/src/Rosetta/containers/Iso9660.luau b/src/Rosetta/containers/Iso9660.luau index 199a53b..9a4ddc2 100644 --- a/src/Rosetta/containers/Iso9660.luau +++ b/src/Rosetta/containers/Iso9660.luau @@ -1,18 +1,8 @@ --!strict --- containers/Iso9660: ISO 9660 (ECMA-119) CD / DVD images, read. The volume descriptors from sector 16 (primary, --- supplementary, boot record, terminator); the directory tree walked through directory records (records never cross --- a sector; multi-extent files are joined; associated files skipped; interleaved files listed, their read is --- Err.UNSUPPORTED). Three name sets: plain ISO 9660 (";1" versions and a lone trailing "." dropped), Joliet (UCS-2 names --- of a supplementary descriptor with the %/@, %/C or %/E escape) and Rock Ridge (SUSP 1.12 / RRIP 1.12 in the --- primary tree: SP, CE continuation areas, NM names, PX modes / links / ids, PN devices, TF times, SL symlinks, CL / RE --- / PL relocated deep directories, with the rr_moved directory hidden when it ends up empty). The tree used is Rock --- Ridge when present, else Joliet, else plain (opts.prefer overrides). El Torito: the boot record's catalog --- (validation entry, initial / default entry) in info.boot. Written from ECMA-119, the SUSP / RRIP 1.12 and Joliet --- specifications and El Torito 1.0; no code ported. Not supported: zisofs (ZF) compressed files (listed; read returns --- the stored bytes), UDF, writing. --- --- local entries, info = Iso9660.read(buf, offset?, length?, opts?) -- { Entry }, Info | nil, Err --- local data, err = Iso9660.extract(buf, base, entry) -- the entry's bytes (a copy of its extents) +-- containers/Iso9660: ISO 9660 (ECMA-119) images, read; from ECMA-119, SUSP / RRIP 1.12, Joliet and El Torito 1.0, no +-- code ported. Name sets: Rock Ridge, else Joliet (%/@, %/C, %/E), else plain (";1" and a trailing "." dropped); +-- multi-extent files joined, CL / RE / PL relocations resolved, El Torito catalog in info.boot. Not supported: zisofs +-- (read returns the stored bytes), interleaved files (Err.UNSUPPORTED), UDF, writing. local Err = require("@rosetta/core/Err") local Types = require("@rosetta/Types") local Text = require("@rosetta/codecs/text/Text") @@ -45,7 +35,6 @@ export type ReadOptions = { local SECTOR = 2048 local S_TYPES: { [number]: string } = { [0x8000] = "0", [0x4000] = "5", [0xA000] = "2", [0x2000] = "3", [0x6000] = "4", [0x1000] = "6", [0xC000] = "s" } --- ------------------------------------------------------------------------------------------------ fields local function u16(b: buffer, o: number): number return buffer.readu16(b, o) end @@ -78,10 +67,8 @@ local function longDate(b: buffer, o: number): number? return Types.Date.toUnix({ kind = "datetime", year = tonumber(y), month = tonumber(mo), day = tonumber(d), hour = tonumber(h), minute = tonumber(mi), second = tonumber(se), offset = off * 15 }) end --- ------------------------------------------------------------------------------------------------ SUSP / Rock Ridge type Susp = { [string]: any } --- the SUSP entries of a system use area (following CE continuation areas) -> { { sig, at, len } } local function suspEntries(b: buffer, base: number, limit: number, o: number, e: number, bs: number, budget: { number }): { { any } } local out = {} while o + 4 <= e do @@ -116,7 +103,6 @@ local function suspEntries(b: buffer, base: number, limit: number, o: number, e: return out end --- Rock Ridge fields of a record: { name, mode, uid, gid, nlink, mtime, link, rdev, child, relocated, zisofs } local function rockRidge(b: buffer, base: number, limit: number, o: number, e: number, bs: number): Susp local rr: Susp = {} local name: { string }? = nil @@ -189,7 +175,6 @@ local function rockRidge(b: buffer, base: number, limit: number, o: number, e: n return rr end --- ------------------------------------------------------------------------------------------------ directories type Record = { name: string, dir: boolean, @@ -202,7 +187,6 @@ type Record = { rr: Susp?, } --- the records of a directory extent (without "." and "..") | nil, Err local function records(b: buffer, base: number, limit: number, at: number, size: number, bs: number, joliet: boolean, rrSkip: number?): ({ Record }?, Err.Err?) if at + size > limit then return nil, Err.new(Err.TRUNCATED, "directory past the end", at) @@ -258,7 +242,6 @@ local function records(b: buffer, base: number, limit: number, at: number, size: return out, nil end --- the root record of a volume descriptor at vd -> lba, size local function root(b: buffer, vd: number): (number, number) return u32(b, vd + 156 + 2), u32(b, vd + 156 + 10) end @@ -281,7 +264,6 @@ local function rockRidgeSkip(b: buffer, base: number, limit: number, lba: number return nil end --- ------------------------------------------------------------------------------------------------ El Torito local function boot(b: buffer, base: number, limit: number, vd: number, bs: number): { [string]: any }? if str(b, vd + 7, 32) ~= "EL TORITO SPECIFICATION" then return nil @@ -309,8 +291,6 @@ local function boot(b: buffer, base: number, limit: number, vd: number, bs: numb return info end --- ------------------------------------------------------------------------------------------------ read --- read(buf, offset?, length?, opts?) -> { Entry }, Info | nil, Err function Iso9660.read(b: buffer, offset: number?, length: number?, opts: ReadOptions?): ({ Entry }?, any) local base = offset or 0 local limit = math.min(buffer.len(b), base + (length or (buffer.len(b) - base))) @@ -498,7 +478,6 @@ function Iso9660.read(b: buffer, offset: number?, length: number?, opts: ReadOpt return out, info end --- extract(buf, entry, limit?) -> a copy of the entry's data | nil, Err function Iso9660.extract(b: buffer, e: Entry, limit: number?): (buffer?, Err.Err?) if e.interleaved then return nil, Err.new(Err.UNSUPPORTED, "interleaved file " .. e.name) @@ -516,7 +495,6 @@ function Iso9660.extract(b: buffer, e: Entry, limit: number?): (buffer?, Err.Err return out, nil end --- valid(buf, offset?) -> true when a volume descriptor "CD001" sits at sector 16 function Iso9660.valid(b: buffer, offset: number?): boolean local p = (offset or 0) + 16 * SECTOR return p + 6 <= buffer.len(b) and buffer.readstring(b, p + 1, 5) == "CD001" diff --git a/src/Rosetta/containers/IsoBmff/Meta.luau b/src/Rosetta/containers/IsoBmff/Meta.luau index 8181e2c..855a563 100644 --- a/src/Rosetta/containers/IsoBmff/Meta.luau +++ b/src/Rosetta/containers/IsoBmff/Meta.luau @@ -32,7 +32,6 @@ local function uint(r: Bytes.Reader, size: number): number return 0 end --- ------------------------------------------------------------------------------------------------ HEIF items export type Property = { type: string, box: Box.Box, [string]: any } export type Item = { id: number, @@ -103,7 +102,6 @@ local function property(b: buffer, box: Box.Box): Property return p end --- items(buf, meta) -> Items | nil, Err (meta: a top-level 'meta' box) function Meta.items(b: buffer, meta: Box.Box): (Items?, Err.Err?) local out: Items = { items = {}, order = {}, properties = {} } local pitm = Box.child(meta, "pitm") @@ -253,8 +251,6 @@ function Meta.items(b: buffer, meta: Box.Box): (Items?, Err.Err?) return out, nil end --- itemData(buf, base, limit, items, id) -> buffer | nil, Err: the item's bytes (extents concatenated); base / limit --- bound the file in the buffer function Meta.itemData(b: buffer, base: number, limit: number, items: Items, id: number): (buffer?, Err.Err?) local it = items.items[id] if not it then @@ -296,7 +292,6 @@ function Meta.itemData(b: buffer, base: number, limit: number, items: Items, id: return out, nil end --- ------------------------------------------------------------------------------------------------ iTunes tags -- ilst item -> standard tag name local TAG: { [string]: string } = { ["\169nam"] = "title", ["\169ART"] = "artist", aART = "albumartist", ["\169alb"] = "album", ["\169day"] = "date", @@ -330,7 +325,6 @@ local GENRES = { export type Picture = { mime: string, data: buffer } --- tags(buf, ilst) -> Tags, { Picture } function Meta.tags(b: buffer, ilst: Box.Box?): ({ [string]: string }, { Picture }) local tags: { [string]: string } = {} local pics: { Picture } = {} @@ -396,7 +390,6 @@ function Meta.tags(b: buffer, ilst: Box.Box?): ({ [string]: string }, { Picture return tags, pics end --- ------------------------------------------------------------------------------------------------ ilst writer local function box(w: Bytes.Writer, typ: string, body: (Bytes.Writer) -> ()) local start = w:tell() w:u32be(0) @@ -426,8 +419,6 @@ local function num(s: string?): number return math.clamp(math.floor(v), 0, 65535) end --- writeIlst(w, tags, pictures?): an ilst box with the tags (standard names -> iTunes atoms; unknown names -> '----' --- freeform com.apple.iTunes items) and cover pictures function Meta.writeIlst(w: Bytes.Writer, tags: { [string]: string }, pictures: { Picture }?) box(w, "ilst", function() local keys = {} @@ -506,7 +497,7 @@ function Meta.writeIlst(w: Bytes.Writer, tags: { [string]: string }, pictures: { end) end --- writeUdta(w, tags, pictures?): udta / meta (hdlr mdir) / ilst +-- udta / meta (hdlr mdir) / ilst function Meta.writeUdta(w: Bytes.Writer, tags: { [string]: string }, pictures: { Picture }?) box(w, "udta", function() box(w, "meta", function() diff --git a/src/Rosetta/containers/IsoBmff/Mux.luau b/src/Rosetta/containers/IsoBmff/Mux.luau index d0474cc..085d554 100644 --- a/src/Rosetta/containers/IsoBmff/Mux.luau +++ b/src/Rosetta/containers/IsoBmff/Mux.luau @@ -1,9 +1,7 @@ --!strict --- containers/IsoBmff/Mux: writes a progressive (non-fragmented) ISO BMFF / MP4 / M4A file: ftyp, moov (mvhd, one trak --- per track with tkhd / edts / mdia / mdhd / hdlr / minf / [sv]mhd / dinf / stbl), the samples interleaved in chunks --- in one mdat, and udta / meta / ilst tags. moov goes first ("fast start"); co64 replaces stco past 4 GB. Sample --- entries: audio (mp4a + esds, alac, Opus + dOps, fLaC + dfLa, ...) and video (avc1 / hvc1 / av01 / vp09 / ... + --- their configuration box), plus any raw child boxes. Never throws: bad specs return nil, Err.ARG. +-- containers/IsoBmff/Mux: writes a progressive ISO BMFF / MP4 / M4A file (ISO/IEC 14496-12): ftyp, moov first ("fast +-- start"), the samples interleaved in chunks in one mdat, udta / meta / ilst tags; co64 past 4 GB. Audio and video +-- sample entries with their configuration box, plus raw child boxes. Never throws: bad specs return nil, Err.ARG. local Err = require("@rosetta/core/Err") local Bytes = require("@rosetta/core/Bytes") local Meta = require("@rosetta/containers/IsoBmff/Meta") @@ -154,7 +152,6 @@ end type Chunk = { track: number, first: number, count: number, time: number, offset: number } --- runs of equal values: { { count, value } } local function runs(n: number, value: (number) -> number): { { number } } local out = {} for i = 1, n do @@ -381,7 +378,6 @@ local function moov(w: Bytes.Writer, spec: MuxSpec, prep: { Prepared }, co64: bo end) end --- mux(spec) -> buffer | nil, Err function Mux.mux(spec: MuxSpec): (buffer?, Err.Err?) if type(spec) ~= "table" or type(spec.tracks) ~= "table" or #spec.tracks == 0 then return nil, Err.new(Err.ARG, "mux: expected { tracks = { ... } }") @@ -476,7 +472,6 @@ function Mux.mux(spec: MuxSpec): (buffer?, Err.Err?) end end local co64 = mdatSize > 4294967295 - 2 ^ 24 - -- ftyp local w = Bytes.writer(mdatSize + 4096) box(w, "ftyp", function() w:string(spec.brand or "isom")