(w, { duration }, bodyFn)
| 189 | // write a frame header with the given chunk-emitting body fn |
| 190 | // bodyFn may be async (e.g. when emitting compressed cels via zlib) |
| 191 | async function writeFrame(w, { duration }, bodyFn) { |
| 192 | const frameStart = w.length; |
| 193 | w.u32(0); // frame size — patched |
| 194 | w.u16(0xf1fa); // frame magic |
| 195 | w.u16(0xffff); // old chunks count: 0xFFFF means "use the 32-bit field below" |
| 196 | w.u16(duration); |
| 197 | w.zeros(2); |
| 198 | const chunkCountOffset = w.length; |
| 199 | w.u32(0); // new chunks count — patched |
| 200 | |
| 201 | let chunkCount = 0; |
| 202 | await bodyFn({ |
| 203 | layer: (name) => { |
| 204 | writeLayerChunk(w, name); |
| 205 | chunkCount++; |
| 206 | }, |
| 207 | rawCel: (opts) => { |
| 208 | writeRawCelChunk(w, opts); |
| 209 | chunkCount++; |
| 210 | }, |
| 211 | linkedCel: (opts) => { |
| 212 | writeLinkedCelChunk(w, opts); |
| 213 | chunkCount++; |
| 214 | }, |
| 215 | compressedCel: async (opts) => { |
| 216 | await writeCompressedCelChunk(w, opts); |
| 217 | chunkCount++; |
| 218 | }, |
| 219 | tags: (tags) => { |
| 220 | writeTagsChunk(w, tags); |
| 221 | chunkCount++; |
| 222 | }, |
| 223 | }); |
| 224 | |
| 225 | const end = w.length; |
| 226 | patchU32WriterPart(w, frameStart, end - frameStart); |
| 227 | patchU32WriterPart(w, chunkCountOffset, chunkCount); |
| 228 | } |
| 229 | |
| 230 | // the writer holds Uint8Array parts before we concat to a buffer, so an |
| 231 | // in-place patch must walk the parts list and mutate the right one. We could |
no test coverage detected