feat(domain): R4.6 ExportSession (incremental export, OD-2): rasters decoded and written on arrival, chunked file handed out in parts, views composed by the core, raster_size_of (O4); wasm ExportSession and CoreExportSession; R4 digests re-frozen (catalog and page tree written last, B2)
This commit is contained in:
1 parent
8d16be577c
commit
9e688b6801
38 files changed
+2421
-354
No files matched your search
@@ -63,6 +63,70 @@ impl SheetHandle {
|
||||
}
|
||||
}
|
||||
|
||||
/// The incremental PDF export (R4.6, plan §B.1.4, OD-2): the application opens a session on
|
||||
/// its `ExportInput` JSON, then alternates `next()` (the rasters the next step needs) with
|
||||
/// `add_raster` or `raster_failed` per key, and closes with `finish()`. Every answer is the
|
||||
/// outcome envelope of the calls; a view raster is decoded and written into the file as it
|
||||
/// arrives (its bytes are copied into linear memory for the call by the glue, and freed
|
||||
/// with the decode before the call returns), so the session holds the file being written
|
||||
/// and nothing of the rasters. `free()` (the driver's `finally`) drops everything it holds.
|
||||
#[wasm_bindgen]
|
||||
pub struct ExportSession {
|
||||
inner: faunosteo_core::pdf::write::session::ExportSession,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl ExportSession {
|
||||
/// Every check of the input, the envelope under its cap, the file opened; throws an
|
||||
/// `Error` worded `<kind>: <detail>` with today's export kinds when the input is refused.
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(input: &str) -> Result<ExportSession, JsError> {
|
||||
faunosteo_core::facade::export::open(input)
|
||||
.map(|inner| ExportSession { inner })
|
||||
.map_err(|failure| JsError::new(&format!("{}: {}", failure.kind, failure.detail)))
|
||||
}
|
||||
|
||||
/// `{"ok":true,"value":<ExportStep>}`: the next batch of raster requests, or `done`.
|
||||
pub fn next_step(&mut self) -> String {
|
||||
faunosteo_core::facade::export::next_step(&mut self.inner)
|
||||
}
|
||||
|
||||
/// The raster of `key` (a PNG); `{"ok":true}` or a closed refusal.
|
||||
pub fn add_raster(&mut self, key: &str, png: &[u8]) -> String {
|
||||
faunosteo_core::facade::export::add_raster(&mut self.inner, key, png)
|
||||
}
|
||||
|
||||
/// `key` could not be rasterised (its warning); `{"ok":true}` or a closed refusal.
|
||||
pub fn raster_failed(&mut self, key: &str) -> String {
|
||||
faunosteo_core::facade::export::raster_failed(&mut self.inner, key)
|
||||
}
|
||||
|
||||
/// Closes the file: the number of parts `take_part()` then gives; throws an `Error`
|
||||
/// worded `<kind>: <detail>` (`out_of_order`, `self_check_failed`).
|
||||
pub fn finish(&mut self) -> Result<u32, JsError> {
|
||||
faunosteo_core::facade::export::finish(&mut self.inner)
|
||||
.map(|parts| u32::try_from(parts).unwrap_or(u32::MAX))
|
||||
.map_err(|failure| JsError::new(&format!("{}: {}", failure.kind, failure.detail)))
|
||||
}
|
||||
|
||||
/// The next part of the finished file, front to back, `undefined` once every part is
|
||||
/// out. Each part is copied out of linear memory by the glue and freed here, so the
|
||||
/// file is never held twice (`new Blob(parts)` takes them as they are).
|
||||
pub fn take_part(&mut self) -> Option<Vec<u8>> {
|
||||
self.inner.take_part()
|
||||
}
|
||||
|
||||
/// `{"ok":true,"value":[<ExportWarning>…]}`, complete after `finish()`.
|
||||
pub fn warnings(&self) -> String {
|
||||
faunosteo_core::facade::export::warnings(&self.inner)
|
||||
}
|
||||
|
||||
/// Bytes of the file written so far (DEV diagnostics only).
|
||||
pub fn written(&self) -> u32 {
|
||||
u32::try_from(self.inner.written()).unwrap_or(u32::MAX)
|
||||
}
|
||||
}
|
||||
|
||||
/// A file's bytes gathered chunk by chunk in the module's memory (R4.3a): the worker reads
|
||||
/// `file.stream()` and pushes each chunk, so the only whole copy of the file is this one.
|
||||
/// The capacity is reserved up front from the file size the worker announces, capped at the
|
||||
|
||||
Reference in new issue
Block a user