Binary Viewer
Binary content viewer web component: images with their size, PDFs in the browser's PDF viewer, and a hex dump with a Download button for anything else.
- 7.4 KB gzipped
- @lit-material/binary-viewer 1.8.0
- Renders on the server
Example
Binary viewer
Shows bytes by content type: an image with its pixel size, a PDF in the browser's own PDF viewer, and anything else as a hex dump
of its first bytes (max-bytes, 4 KiB by default). Every view offers Download. data takes a
Uint8Array, an ArrayBuffer or a Blob.
Image
Image
image/png
Download
No content
PDF
application/pdf
Download
No content
Anything else
Binary
application/zip
Download
No content
Install
npm install @lit-material/binary-viewer @lit-material/tokens
import "@lit-material/binary-viewer";
Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide
API
<lit-material-binary-viewer>
Shows binary content, like a response body or an uploaded file, by its content type:
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
data | property only | BinaryData | null | null | The content: bytes or a Blob. Property only. |
contentType | content-type | string | "" | Its content type, e.g. image/png (parameters such as ; charset are ignored). Default: a Blob's own type. |
filename | filename | string | "" | The file name Download saves as, and the name the views use. |
maxBytes | max-bytes | number | 4096 | How many bytes the hex dump shows (rounded up to whole rows of 16). |
type | property only | string | none | The content type in use: content-type, else a Blob's own type. |
view | property only | BinaryView | none | The view the content gets. |
Events
| Event | Description |
|---|---|
download | Download was pressed; detail: {blob, filename}, cancelable. |
CSS parts
| Part | Description |
|---|---|
facts | The line saying what the content is, with the Download button. |
image | The <img>. |
frame | The PDF viewer (<object>). |
dump | The hex dump's scrolling box. |
CSS custom properties
| Property | Description |
|---|---|
--lit-material-binary-viewer-max-height | The tallest the image, frame or hex dump gets (default 480px). |