decklight 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/PLATFORM.md +666 -0
  2. package/README.md +224 -150
  3. package/SPEC.md +732 -886
  4. package/cli/agent-review.mjs +245 -0
  5. package/cli/agents.mjs +25 -5
  6. package/cli/associate.mjs +12 -12
  7. package/cli/audit.mjs +42 -10
  8. package/cli/banner.mjs +41 -17
  9. package/cli/bundle-audio.mjs +183 -0
  10. package/cli/bundle.mjs +383 -31
  11. package/cli/cast.mjs +7 -7
  12. package/cli/check.mjs +961 -0
  13. package/cli/clone-deck.mjs +179 -0
  14. package/cli/commands.mjs +345 -0
  15. package/cli/comments.mjs +64 -18
  16. package/cli/commit-flow.mjs +44 -19
  17. package/cli/commit-message.mjs +51 -74
  18. package/cli/commit-split.mjs +601 -0
  19. package/cli/deck-refs.mjs +59 -0
  20. package/cli/deck-routes.mjs +67 -0
  21. package/cli/deckfile.mjs +3 -5
  22. package/cli/decklight.mjs +68 -289
  23. package/cli/design-system-deps.mjs +209 -0
  24. package/cli/design-system-edit.mjs +194 -0
  25. package/cli/design-system-refs.mjs +409 -0
  26. package/cli/design-system.mjs +429 -0
  27. package/cli/doctor.mjs +115 -0
  28. package/cli/edit-git.mjs +353 -0
  29. package/cli/edit-handover.mjs +445 -0
  30. package/cli/edit-look.mjs +388 -0
  31. package/cli/edit-slides.mjs +683 -0
  32. package/cli/edit.mjs +2126 -842
  33. package/cli/enhance.mjs +483 -0
  34. package/cli/extension.mjs +10 -10
  35. package/cli/font-refs.mjs +273 -0
  36. package/cli/font.mjs +246 -0
  37. package/cli/git-tree.mjs +1 -1
  38. package/cli/git.mjs +65 -11
  39. package/cli/import.mjs +56 -10
  40. package/cli/init.mjs +400 -234
  41. package/cli/library.mjs +127 -0
  42. package/cli/loader.mjs +3 -1
  43. package/cli/marketplace.mjs +215 -21
  44. package/cli/narrate.mjs +176 -0
  45. package/cli/open-browser.mjs +63 -0
  46. package/cli/open.mjs +943 -0
  47. package/cli/pdf.mjs +41 -13
  48. package/cli/pkg.mjs +44 -2
  49. package/cli/plugin.mjs +43 -41
  50. package/cli/port-conflict.mjs +53 -23
  51. package/cli/pptx-export.mjs +71 -26
  52. package/cli/publish.mjs +8 -4
  53. package/cli/qr.mjs +1 -1
  54. package/cli/record.mjs +14 -12
  55. package/cli/remote.mjs +11 -11
  56. package/cli/restore.mjs +11 -4
  57. package/cli/review-ref.mjs +125 -0
  58. package/cli/review-remote.mjs +92 -48
  59. package/cli/review-routes.mjs +254 -0
  60. package/cli/review-store.mjs +47 -7
  61. package/cli/review-submit.mjs +47 -57
  62. package/cli/runtime-link.mjs +560 -0
  63. package/cli/serve.mjs +235 -44
  64. package/cli/setup.mjs +112 -0
  65. package/cli/sign.mjs +1 -1
  66. package/cli/skill-content.mjs +190 -33
  67. package/cli/skills.mjs +107 -24
  68. package/cli/start.mjs +110 -0
  69. package/cli/supervise.mjs +6 -6
  70. package/cli/theme-refs.mjs +515 -0
  71. package/cli/theme.mjs +181 -137
  72. package/cli/trust.mjs +83 -0
  73. package/cli/units.mjs +39 -42
  74. package/cli/update-check.mjs +1 -5
  75. package/cli/upgrade.mjs +194 -28
  76. package/cli/upstream.mjs +4 -3
  77. package/cli/util.mjs +4 -4
  78. package/cli/wizard.mjs +6 -6
  79. package/dist/build-info.json +1 -1
  80. package/dist/decklight.css +1126 -49
  81. package/dist/decklight.js +212 -115
  82. package/dist/decklight.js.map +4 -4
  83. package/docs/GLOSSARY.md +141 -0
  84. package/docs/architecture.svg +17 -17
  85. package/package.json +4 -2
  86. package/themes/README.md +9 -8
  87. package/themes/reveal-solarized.css +10 -0
  88. package/tools/args.mjs +20 -0
  89. package/tools/atomic-write.mjs +48 -0
  90. package/tools/brand-palette.mjs +717 -0
  91. package/tools/bridge.mjs +1 -1
  92. package/tools/build-groups.mjs +42 -0
  93. package/tools/color.mjs +48 -0
  94. package/tools/deck-html.mjs +396 -11
  95. package/tools/design-system-format.mjs +753 -0
  96. package/tools/elevenlabs-tts.mjs +110 -17
  97. package/tools/exec.mjs +35 -2
  98. package/tools/extension-check.mjs +31 -7
  99. package/tools/font-format.mjs +190 -0
  100. package/tools/font-stacks.mjs +24 -0
  101. package/tools/gemini-tts.mjs +3 -0
  102. package/tools/lipsync-config.mjs +103 -0
  103. package/tools/lipsync-engines.mjs +205 -2
  104. package/tools/lipsync-server.mjs +264 -41
  105. package/tools/lipsync.mjs +37 -18
  106. package/tools/local-voice.mjs +32 -42
  107. package/tools/narration-manifest.mjs +196 -0
  108. package/tools/narration-synth.mjs +416 -0
  109. package/tools/pptx.mjs +776 -19
  110. package/tools/publish-targets.mjs +1 -1
  111. package/tools/publish-voices.mjs +3 -3
  112. package/tools/recording-impact.mjs +7 -3
  113. package/tools/render-theme.mjs +33 -0
  114. package/tools/review-anchor.mjs +28 -12
  115. package/tools/semver.mjs +40 -0
  116. package/tools/sentences.mjs +180 -0
  117. package/tools/shot.mjs +14 -7
  118. package/tools/site-voices.mjs +232 -0
  119. package/tools/template-theme.mjs +1 -1
  120. package/tools/test-impact.mjs +19 -10
  121. package/tools/theme-check.mjs +30 -3
  122. package/tools/tts-cache.mjs +4 -3
  123. package/tools/tts-engines.mjs +38 -20
  124. package/tools/tts-setup.mjs +7 -7
  125. package/tools/video-options.mjs +34 -0
  126. package/tools/video.mjs +461 -48
  127. package/tools/voiceover-server.mjs +185 -104
  128. package/tools/voiceover.mjs +119 -261
  129. package/tools/zip.mjs +1 -1
  130. package/cli/dev.mjs +0 -623
  131. package/cli/present.mjs +0 -853
  132. package/cli/review.mjs +0 -361
  133. package/tools/publish-site-voices.mjs +0 -75
package/cli/banner.mjs CHANGED
@@ -2,9 +2,9 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  /**
5
- * One banner for `decklight author`, and the deck's URL is the last thing on it.
5
+ * One banner for `decklight <deck>`, and the deck's URL is the last thing on it.
6
6
  *
7
- * author runs its servers as child processes and used to let each one print its
7
+ * the edit server runs its servers as child processes and used to let each one print its
8
8
  * own startup lines through a pipe that did nothing but prefix them. That gave
9
9
  * two problems no amount of rewording fixes:
10
10
  *
@@ -17,9 +17,9 @@
17
17
  * together were a wall, because no single place could see them all and
18
18
  * decide what mattered.
19
19
  *
20
- * So author prints the banner and the children stop printing startup lines —
20
+ * So `open` prints the banner and the children stop printing startup lines —
21
21
  * they hand author a FACT instead, on the same pipe, behind a sentinel
22
- * (`readyLine`). Only under author: with no `DECKLIGHT_BANNER` in the
22
+ * (`readyLine`). Only in write mode: with no `DECKLIGHT_BANNER` in the
23
23
  * environment every child prints exactly what it printed before, which is what
24
24
  * `decklight edit` and `decklight tts` run on their own still do.
25
25
  *
@@ -54,17 +54,41 @@ export function parseReady(line) {
54
54
  * The order rows appear in, whatever order the processes woke up in — which is
55
55
  * the entire point of collecting them all before printing any.
56
56
  *
57
- * `reviews` is last because it is the only row that is a THING TO DO rather
58
- * than a thing that is merely true, so it sits closest to the URL.
57
+ * The facts come first. Then the rows that are a THING TO DO rather than a
58
+ * thing that is merely true, `runtime` and `skill` (each ends in the command
59
+ * that fixes it), then `reviews`, which sits closest to the URL. `runtime` and
60
+ * `skill` used to be missing here, so they kept their arrival position after
61
+ * every known row and landed below `reviews`.
59
62
  */
60
- export const ROW_ORDER = ['voice', 'lips', 'skipped', 'git', 'agents', 'reviews'];
63
+ export const ROW_ORDER = ['port', 'voice', 'lips', 'skipped', 'git', 'agents', 'plugins', 'runtime', 'skill', 'reviews'];
61
64
 
62
- const ESC = { dim: '\x1b[2m', bold: '\x1b[1m', cyan: '\x1b[36m', under: '\x1b[4m', reset: '\x1b[0m' };
65
+ const ESC = { dim: '\x1b[2m', bold: '\x1b[1m', cyan: '\x1b[36m', green: '\x1b[32m', yellow: '\x1b[33m', red: '\x1b[31m', under: '\x1b[4m', reset: '\x1b[0m' };
63
66
 
64
67
  /**
65
- * The banner, as lines. `rows` is `[{ key, text }]` in any order; a key not in
66
- * ROW_ORDER keeps its arrival position after the known ones, so a service added
67
- * later still appears without anyone having to remember to edit that list.
68
+ * The mark in front of a row: ✓ for something installed and on, ! for
69
+ * something to fix, ✗ for something that failed and is not running, nothing
70
+ * for a plain fact. A fact says which with `mark`.
71
+ */
72
+ export function rowMark(mark, color = false) {
73
+ const c = (s, k) => (color ? ESC[k] + s + ESC.reset : s);
74
+ if (mark === 'ok') return c('\u2713', 'green');
75
+ if (mark === 'warn') return c('!', 'yellow');
76
+ if (mark === 'fail') return c('\u2717', 'red');
77
+ return ' ';
78
+ }
79
+
80
+ /** One row, as `renderBanner` prints it and as a late fact is printed after it. */
81
+ export function bannerRow({ key, text, mark }, { width = key.length, color = false } = {}) {
82
+ const k = color ? ESC.dim + key.padEnd(width) + ESC.reset : key.padEnd(width);
83
+ return ` ${rowMark(mark, color)} ${k} ${text}`;
84
+ }
85
+
86
+ /**
87
+ * The banner, as lines. `rows` is `[{ key, text, mark }]` in any order; a key
88
+ * not in ROW_ORDER keeps its arrival position after the known ones, so a
89
+ * service added later still appears without anyone having to remember to edit
90
+ * that list. `deck` is a header line, given only when debugging: the version
91
+ * line above the banner and the URL below it already name what is running.
68
92
  */
69
93
  export function renderBanner({ deck, url, keys, rows = [], color = false } = {}) {
70
94
  const c = (s, ...codes) => (color ? codes.map((k) => ESC[k]).join('') + s + ESC.reset : s);
@@ -74,11 +98,11 @@ export function renderBanner({ deck, url, keys, rows = [], color = false } = {})
74
98
  .map((r, i) => ({ ...r, i }))
75
99
  .sort((a, b) => rank(a.key) - rank(b.key) || a.i - b.i);
76
100
 
77
- const out = [`decklight author${deck ? ` ${c('·', 'dim')} ${deck}` : ''}`];
101
+ const out = deck ? [`decklight ${c('·', 'dim')} ${deck}`] : [];
78
102
  if (shown.length) {
79
- out.push('');
80
- const w = Math.max(...shown.map((r) => r.key.length));
81
- for (const r of shown) out.push(` ${c(r.key.padEnd(w), 'dim')} ${r.text}`);
103
+ if (out.length) out.push('');
104
+ const width = Math.max(...shown.map((r) => r.key.length));
105
+ for (const r of shown) out.push(bannerRow(r, { width, color }));
82
106
  }
83
107
  // The URL last, and the only coloured thing here, because a person scanning
84
108
  // this is looking for exactly one thing and it is this.
@@ -110,13 +134,13 @@ export function nextFlushDelay({ waiting = 0, elapsed = 0, cap = 5000, grace = 3
110
134
  * How anything WATCHING author's output finds the deck's url.
111
135
  *
112
136
  * Exported because six harnesses each carried their own copy of the old
113
- * `decklight author on http://…`, and the day that line changed shape all six
137
+ * `decklight · <deck> on http://…`, and the day that line changed shape all six
114
138
  * timed out for the same reason in six different files. A banner is a thing
115
139
  * people read, so its wording will change again; this is the part that is a
116
140
  * contract, and it lives next to the code that prints it.
117
141
  *
118
142
  * Group 1 is the port. Tolerant of the colour codes a terminal gets and a pipe
119
- * does not, so it matches whichever way author was run — and the escapes and
143
+ * does not, so it matches whichever way `open` was run — and the escapes and
120
144
  * the space INTERLEAVE: the reset that closes the ▸ lands between the arrow
121
145
  * and the space before the url. A pattern that expected the whitespace first
122
146
  * matched every piped harness and none of the ones driven through a pty,
@@ -0,0 +1,183 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // The narration's recorded audio in a bundle (SPEC DECK_ANATOMY): which files a
5
+ // deck's tracks play, how big each way of carrying them would make the file,
6
+ // and the blocks that carry them.
7
+ //
8
+ // Three ways, and leaving it out is a fourth:
9
+ //
10
+ // original the files as recorded: nothing lost, nothing gained
11
+ // aac mono AAC at 32 kbps, about 4 KB a second of voice: plays in
12
+ // every browser, which is what a file that is SENT needs
13
+ // opus mono Opus at 24 kbps in WebM, about 3 KB a second and better
14
+ // at that rate than AAC: the smallest, for a recent browser
15
+ // (Safari from 17)
16
+ //
17
+ // A recorder WAV is about forty times the AAC. A re-encode that would not
18
+ // shrink a file leaves it as it was: encoding an already-small file again only
19
+ // loses. Every block is keyed by the URL the track would play, which is what
20
+ // the runtime looks up before playing that URL (narration.js bundledAudio).
21
+
22
+ import fs from 'node:fs';
23
+ import os from 'node:os';
24
+ import path from 'node:path';
25
+ import { configuredTrackDirs } from './edit.mjs';
26
+ import { runAsync, CODEC_MS, PROBE_MS } from '../tools/exec.mjs';
27
+
28
+ export const AUDIO_CHOICES = ['original', 'aac', 'opus'];
29
+
30
+ export const CODECS = {
31
+ aac: {
32
+ label: 'AAC, mono 32 kbps', kbps: 32, overhead: 1.03, ext: 'm4a', mime: 'audio/mp4', encoder: 'aac',
33
+ args: ['-ac', '1', '-ar', '24000', '-c:a', 'aac', '-b:a', '32k', '-movflags', '+faststart'],
34
+ },
35
+ opus: {
36
+ label: 'Opus, mono 24 kbps', kbps: 24, overhead: 1.09, ext: 'webm', mime: 'audio/webm', encoder: 'libopus',
37
+ // constrained VBR: the size stays near the bitrate whatever was recorded,
38
+ // which is what lets the bundle card's estimate be one
39
+ args: ['-ac', '1', '-c:a', 'libopus', '-b:a', '24k', '-vbr', 'constrained', '-application', 'voip'],
40
+ },
41
+ };
42
+
43
+ const AUDIO_MIME = {
44
+ m4a: 'audio/mp4', mp4: 'audio/mp4', aac: 'audio/aac', mp3: 'audio/mpeg', wav: 'audio/wav',
45
+ ogg: 'audio/ogg', oga: 'audio/ogg', opus: 'audio/ogg', webm: 'audio/webm', flac: 'audio/flac',
46
+ };
47
+ const AUDIO_FILE = /^slide-\d+(?:-\d+)?\.(m4a|mp4|aac|mp3|wav|ogg|oga|opus|webm|flac)$/i;
48
+ const ABSOLUTE = /^[a-z][a-z0-9+.-]*:|^\/\//i;
49
+
50
+ /** "1.4 MB", "820.3 KB". */
51
+ export const sizeLabel = (n) => (n < 1048576 ? `${(n / 1024).toFixed(1)} KB` : `${(n / 1048576).toFixed(1)} MB`);
52
+
53
+ /**
54
+ * Every recorded file a deck's tracks would play from this disk: a
55
+ * `narration.files` folder's `slide-NN[-KK].<audio>`, and a local manifest's
56
+ * `file` entries. `found` maps the URL the runtime plays to the file;
57
+ * `folders` reads "voices/ (12), cloud/ (3)"; `remote` counts manifest entries
58
+ * with a `url` of their own (a bucket's, often signed), which stay there.
59
+ */
60
+ export function narrationAudio(html, deckDir) {
61
+ const found = new Map();
62
+ const where = new Map();
63
+ const add = (key, abs) => {
64
+ if (found.has(key) || !fs.existsSync(abs) || !fs.statSync(abs).isFile()) return;
65
+ found.set(key, abs);
66
+ const folder = path.posix.dirname(key);
67
+ where.set(folder, (where.get(folder) ?? 0) + 1);
68
+ };
69
+ for (const d of configuredTrackDirs(html)) {
70
+ if (ABSOLUTE.test(d)) continue; // a public bucket's prefix: nothing on this disk
71
+ const abs = path.resolve(deckDir, d);
72
+ if (!fs.existsSync(abs) || !fs.statSync(abs).isDirectory()) continue;
73
+ for (const f of fs.readdirSync(abs).sort()) if (AUDIO_FILE.test(f)) add(`${d.replace(/\/+$/, '')}/${f}`, path.join(abs, f));
74
+ }
75
+ let remote = 0;
76
+ // `manifest: '…'` in a boot call, `"manifest": "…"` in a configuration block
77
+ for (const rel of new Set([...html.matchAll(/\bmanifest["']?\s*:\s*['"]([^'"]+)['"]/g)].map((m) => m[1]))) {
78
+ const abs = path.resolve(deckDir, rel);
79
+ let data = null;
80
+ try { data = JSON.parse(fs.readFileSync(abs, 'utf8')); } catch { continue; }
81
+ const clean = rel.replace(/[?#].*$/, '');
82
+ const base = clean.slice(0, clean.lastIndexOf('/') + 1); // voicetrack.js manifestBase
83
+ const entries = (data?.slides ?? []).flatMap((e) => (e ? [e, ...(e.segments ?? []).filter(Boolean)] : []));
84
+ for (const e of entries) {
85
+ if (e.url) { remote++; continue; }
86
+ if (typeof e.file !== 'string' || ABSOLUTE.test(e.file)) continue;
87
+ add(base + e.file, path.resolve(path.dirname(abs), e.file));
88
+ }
89
+ }
90
+ return { found, remote, folders: [...where].map(([f, n]) => `${f}/ (${n})`).join(', ') };
91
+ }
92
+
93
+ /** The block one file goes in, as the bundle writes it. */
94
+ function block(key, mime, buf) {
95
+ return `<script type="application/json" data-decklight-audio="${key.replace(/"/g, '&quot;')}">`
96
+ + `${JSON.stringify(`data:${mime};base64,${buf.toString('base64')}`)}</script>`;
97
+ }
98
+ /** That block's length for `n` bytes, without building it. */
99
+ const blockLength = (key, mime, n) => block(key, mime, Buffer.alloc(0)).length + 4 * Math.ceil(n / 3) + 1;
100
+
101
+ /** Which of the two encoders this machine's ffmpeg has: `{ aac, opus }`, both false without one. */
102
+ export async function encoders() {
103
+ try {
104
+ const out = String(await runAsync('ffmpeg', ['-hide_banner', '-encoders'], { timeout: PROBE_MS, why: 'listing encoders' }));
105
+ return { aac: /^\s*A\S*\s+aac\s/m.test(out), opus: /^\s*A\S*\s+libopus\s/m.test(out) };
106
+ } catch { return { aac: false, opus: false }; }
107
+ }
108
+
109
+ /** A file's length in seconds, or null when ffprobe cannot say. */
110
+ async function duration(abs) {
111
+ try {
112
+ const out = await runAsync('ffprobe', ['-v', 'error', '-show_entries', 'format=duration', '-of', 'csv=p=0', abs],
113
+ { timeout: PROBE_MS, why: 'reading a duration' });
114
+ const s = Number.parseFloat(String(out));
115
+ return Number.isFinite(s) ? s : null;
116
+ } catch { return null; }
117
+ }
118
+
119
+ /**
120
+ * What each choice would add to the file, in bytes, before anything is
121
+ * encoded: `original` exactly; `aac` and `opus` from each file's duration at
122
+ * the codec's bitrate, plus what its container adds (measured: 3% for MP4,
123
+ * 9% for WebM), never more than the file itself, because a re-encode that
124
+ * would not shrink it is skipped.
125
+ * A codec this ffmpeg lacks, or durations ffprobe cannot read, give null with
126
+ * the reason in `why`.
127
+ */
128
+ export async function estimateAudio(found) {
129
+ const files = [...found];
130
+ const have = await encoders();
131
+ const seconds = await Promise.all(files.map(([, abs]) => duration(abs)));
132
+ const known = seconds.every((s) => s != null);
133
+ const sizes = files.map(([, abs]) => fs.statSync(abs).size);
134
+ const original = files.reduce((n, [key, abs], i) => n + blockLength(key, AUDIO_MIME[path.extname(abs).slice(1).toLowerCase()], sizes[i]), 0);
135
+ const out = { files: files.length, bytes: sizes.reduce((a, b) => a + b, 0), seconds: known ? seconds.reduce((a, b) => a + b, 0) : null, original, why: {} };
136
+ for (const [name, c] of Object.entries(CODECS)) {
137
+ if (!have[name]) { out[name] = null; out.why[name] = `needs ffmpeg with ${c.encoder}`; continue; }
138
+ if (!known) { out[name] = null; out.why[name] = 'ffprobe could not read the durations'; continue; }
139
+ out[name] = files.reduce((n, [key, abs], i) => {
140
+ const encoded = Math.ceil(seconds[i] * c.kbps * 1000 / 8 * c.overhead) + 1024;
141
+ return n + (encoded < sizes[i] ? blockLength(key, c.mime, encoded)
142
+ : blockLength(key, AUDIO_MIME[path.extname(abs).slice(1).toLowerCase()], sizes[i]));
143
+ }, 0);
144
+ }
145
+ return out;
146
+ }
147
+
148
+ /**
149
+ * The blocks that carry `found`, as recorded or re-encoded with `codec`
150
+ * ('original' | 'aac' | 'opus'). Throws an Error with a sentence when ffmpeg
151
+ * is missing or refuses a file. Returns `{ blocks, bytes, before }`.
152
+ */
153
+ export async function inlineAudio(found, codec = 'original') {
154
+ const c = CODECS[codec] ?? null;
155
+ const scratch = c ? fs.mkdtempSync(path.join(os.tmpdir(), 'decklight-audio-')) : null;
156
+ const blocks = [];
157
+ let bytes = 0, before = 0, nth = 0;
158
+ try {
159
+ for (const [key, abs] of found) {
160
+ let buf = fs.readFileSync(abs);
161
+ let mime = AUDIO_MIME[path.extname(abs).slice(1).toLowerCase()];
162
+ before += buf.length;
163
+ if (c) {
164
+ const out = path.join(scratch, `${++nth}.${c.ext}`);
165
+ try {
166
+ await runAsync('ffmpeg', ['-hide_banner', '-loglevel', 'error', '-y', '-i', abs, '-vn', ...c.args, out],
167
+ { timeout: CODEC_MS, why: `re-encoding ${key}` });
168
+ } catch (e) {
169
+ if (e.code === 'ENOENT') throw new Error(`--audio ${codec} re-encodes the narration with ffmpeg, which is not installed — install it, or bundle with --audio original to carry the files as they are`);
170
+ throw new Error(`--audio ${codec} could not re-encode ${key}: ${String(e.stderr || e.message).trim().split('\n')[0]}`);
171
+ }
172
+ const small = fs.readFileSync(out);
173
+ // an already-small file stays as it was: re-encoding it again only loses
174
+ if (small.length < buf.length) { buf = small; mime = c.mime; }
175
+ }
176
+ bytes += buf.length;
177
+ blocks.push(block(key, mime, buf));
178
+ }
179
+ } finally {
180
+ if (scratch) fs.rmSync(scratch, { recursive: true, force: true });
181
+ }
182
+ return { blocks, bytes, before };
183
+ }