FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
Gj64
Gj64untitled-1852
Public
Like
untitled-1852
Home
Code
3
backend
2
frontend
1
README.md
Branches
1
Pull requests
Remixes
History
Environment variables
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.
Sign up now
Code
/
backend
/
README.md
Code
/
backend
/
README.md
Search
5/18/2025
Viewing readonly version of main branch: v5
View latest version
README.md

LDOC Viewer Backend

This directory contains the backend implementation for the LDOC Viewer application.

Overview

The backend provides:

  1. LDOC format implementation (reader and writer classes)
  2. API endpoints for handling LDOC operations
  3. Static file serving for the frontend

Core Components

LDOC Writer

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

LDOC Reader

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

API Endpoints

The backend exposes the following API endpoints:

  • POST /api/encode: Creates an LDOC container from uploaded files
  • POST /api/info: Returns metadata about an LDOC container
  • POST /api/extract: Extracts all files from an LDOC container as a ZIP archive
  • POST /api/view: Returns a list of files in an LDOC container with metadata
  • POST /api/view/file: Returns the content of a specific file from an LDOC container

File Type Detection

The backend includes helper functions for detecting file types:

  • isTextFile: Determines if a file is a text file based on extension or MIME type
  • isImageFile: Determines if a file is an image based on extension or MIME type
  • isViewableFile: Determines if a file can be viewed in the browser

LDOC Format Specification

The LDOC format consists of:

  1. 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)
  2. Manifest:

    • CBOR-encoded array of objects
    • Each object contains metadata about a file in the container
  3. File Data:

    • Compressed file contents using zlib
  4. Trailer:

    • JSON-encoded revision history
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.