Public
Like
untitled-1852
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v5View latest version
This directory contains the backend implementation for the LDOC Viewer application.
The backend provides:
- LDOC format implementation (reader and writer classes)
- API endpoints for handling LDOC operations
- Static file serving for the frontend
The LDOCWriter
class handles the creation of LDOC containers:
- Compresses files using zlib
- Detects file types and MIME types
- Creates the LDOC manifest
- Assembles the final container with header, manifest, file data, and trailer
The LDOCReader
class handles the extraction and inspection of LDOC containers:
- Parses the LDOC header
- Reads the manifest
- Extracts files from the container
- Provides metadata about the container and its contents
The backend exposes the following API endpoints:
POST /api/encode
: Creates an LDOC container from uploaded filesPOST /api/info
: Returns metadata about an LDOC containerPOST /api/extract
: Extracts all files from an LDOC container as a ZIP archivePOST /api/view
: Returns a list of files in an LDOC container with metadataPOST /api/view/file
: Returns the content of a specific file from an LDOC container
The backend includes helper functions for detecting file types:
isTextFile
: Determines if a file is a text file based on extension or MIME typeisImageFile
: Determines if a file is an image based on extension or MIME typeisViewableFile
: Determines if a file can be viewed in the browser
The LDOC format consists of:
-
Header (32 bytes):
- Magic bytes "LDOC01" (6 bytes)
- Version (1 byte)
- Flags (1 byte)
- Manifest length (4 bytes)
- Manifest offset (8 bytes)
- Trailer offset (8 bytes)
- Reserved (4 bytes)
-
Manifest:
- CBOR-encoded array of objects
- Each object contains metadata about a file in the container
-
File Data:
- Compressed file contents using zlib
-
Trailer:
- JSON-encoded revision history