Media / foldkit-media
Facts
An ImageAsset's facts are derived from its original once, where it enters,
and stored beside it. describe is in the core; each inspector is the
subpath of where it runs (/sharp, /browser, /cloudflare), and factsOf
is foldkit-media/server's:
describe(key, bytes)reads them through theInspector: size, alpha, the SHA-256, and a ThumbHash where the inspector makes a thumbnail.inspectorSharp({ maxPixels? })(Node) reads all of them; alpha is whether any pixel is transparent, so an opaque PNG still gets a placeholder.inspectorBrowser({ maxPixels? })(foldkit-media/browser) reads them in the browser or a web worker, with its own decoder: an editor describes a file a reader dropped, ThumbHash and hash included, before anything is uploaded, and stores its facts beside the image (a rich-textImage'sasset). What the browser cannot decode is refused.inspectorImages(binding)(Cloudflare) reads the size frominfo, which costs no transformation. It makes no thumbnail, since the binding's raw pixels are not offered offline, and takes every format but JPEG to be transparent; both cost a placeholder, never show a wrong one.factsOf(url, { allow, maxBytes?, cache?, fetch? })describes an image a page names only by URL (a rich-text image), so it gets its box like any other. Onlyhttpson a host inallow(matched exactly), at its default port, is read, each redirect is checked again, and the body is limited as it streams. Given aKeyValueStoreascache, the facts are kept by URL and the original is asked for again with itsETag, so an unchanged one is not read twice.