Data upload via external file like the json,csv?
Closed this issue · 1 comments
Hi again,
Greetings.
I would like to know if it is possible to upload the data via an external file like json, csv etc as it is supported by the typst? If it does not already but there is a way to achieve this, please let me know.
Thanks for such an amazing library and your support, friend.
Hi, you could add files to your access model, which can then get read by typst compiler. The access model refers to
You can also use the {map,unmap,reset}Shadow
function to manipulate any text or binary file data for typst compiler. They will shadow the file access from provided access model directly in memory.
typst.ts/packages/typst.ts/src/compiler.mts
Lines 69 to 95 in 4ef85dc
The mapShadow(path: string, content: Uint8Array): void;
resembles addSource(path: string, source: string): void;
, but retrieves some binary data without guessing the underlying encoding.
Example usage:
const encoder = new TextEncoder();
// add a json file (utf8)
compiler.mapShadow('/assets/data.json', encoder.encode(jsonData));
// remove a json file
compiler.unmapShadow('/assets/data.json');
// clean up all shadow files (Note: this function will also clean all files added by `addSource`)
compiler.resetShadow();
// add an image file
const pngData = await fetch(...).arrayBuffer();
compiler.mapShadow('/assets/tiger.png', new Uint8Array(pngData));