My aggregated monorepo of OCaml code, automaintained
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add Zstd decompression to browser backend via fzstd.js

- tessera_zarr_jsoo: register "zstd" codec using fzstd.decompress
(Uint8Array → Uint8Array), bridged to OCaml strings
- Notebook setup: load fzstd@0.1.1 via importScripts before TF.js
- Blosc.decode handles the full pipeline: parse header → extract
compressed payload → fzstd decompress → bitshuffle unshuffle
- Fixes "compressed frame but no decompressor provided" error

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+24 -4
+5 -3
site/notebooks/interactive_map_zarr.mld
··· 14 14 #require "tessera-tfjs";; 15 15 #require "js_top_worker-widget-leaflet";; 16 16 Widget_leaflet.register ();; 17 - (* Load TensorFlow.js *) 17 + (* Load TensorFlow.js and fzstd (Zstd decompressor) *) 18 18 let () = 19 19 let open Js_of_ocaml in 20 - Js.Unsafe.fun_call 20 + let import url = Js.Unsafe.fun_call 21 21 (Js.Unsafe.get Js.Unsafe.global (Js.string "importScripts")) 22 - [| Js.Unsafe.inject (Js.string "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4/dist/tf.min.js") |] 22 + [| Js.Unsafe.inject (Js.string url) |] in 23 + import "https://cdn.jsdelivr.net/npm/fzstd@0.1.1/umd/index.js"; 24 + import "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4/dist/tf.min.js" 23 25 ]} 24 26 25 27 {1 Reactive pipeline}
+19 -1
tessera-zarr-jsoo/lib/tessera_zarr_jsoo.ml
··· 53 53 | code -> 54 54 failwith (Printf.sprintf "HTTP %d fetching %s" code url) 55 55 56 - let codecs _name = None 56 + (* Zstd decompressor via fzstd.js (must be loaded via importScripts). 57 + fzstd.decompress takes a Uint8Array and returns a Uint8Array. *) 58 + let zstd_decompress data = 59 + let fzstd = Js.Unsafe.global##.fzstd in 60 + if not (Js.Optdef.test fzstd) then 61 + failwith "fzstd not loaded. Add importScripts for fzstd in setup cell."; 62 + (* Convert OCaml string → Uint8Array *) 63 + let input = Typed_array.Bytes.to_uint8Array (Bytes.of_string data) in 64 + (* Call fzstd.decompress(uint8array) → uint8array *) 65 + let output : Typed_array.uint8Array Js.t = 66 + Js.Unsafe.meth_call fzstd "decompress" 67 + [| Js.Unsafe.inject input |] in 68 + (* Convert Uint8Array → OCaml string via ArrayBuffer *) 69 + Typed_array.String.of_uint8Array output 70 + 71 + let codecs name = 72 + match name with 73 + | "zstd" -> Some zstd_decompress 74 + | _ -> None 57 75 58 76 let open_store ?(base_url = "https://dl2.geotessera.org/zarr/v1") 59 77 ?(year = 2024) () =