Code Samples & Integration Reference

Programmatic examples for accessing, parsing, and reconstructing early web archives. All endpoints return WARC-compliant payloads.

1. Fetching Archived Snapshots

Retrieve timestamped page captures using the Archive Gateway. Supports range queries and format negotiation.

JAVASCRIPT
const { ArchiveClient } = require('@1990-archive/sdk');

const client = new ArchiveClient({ apiKey: process.env.ARC_KEY });

// Fetch all captures for a specific URL between 1996-1999
async function getSnapshots() {
  const res = await client.capture.query({
    url: 'http://www.geocities.com/~retro_user',
    start: '1996-01-01',
    end:   '1999-12-31',
    format: 'warc/raw'
  });

  console.log(`Found ${res.total} snapshots`);
  return res.payloads.slice(0, 3);
}

getSnapshots().then(snapshots => {
  snapshots.forEach(s => console.log(s.timestamp, s.size));
});
Found 42 snapshots 1997-03-14T08:22:01Z 142KB 1998-11-02T14:05:33Z 189KB 1999-08-19T21:11:07Z 203KB

2. Parsing Frameset & Table Layouts

Legacy pages heavily relied on <frameset> and nested tables. Use the structural resolver to flatten layouts into modern DOM trees.

Note: The legacy_flatten flag automatically rewrites FRAME boundaries into <div> containers while preserving original inline styles.
PYTHON
from archive_parser import LegacyHTMLResolver
from bs4 import BeautifulSoup

def flatten_frameset(raw_html: str) -> str:
    resolver = LegacyHTMLResolver(mode="strict_1998")
    tree = resolver.parse(raw_html, flatten_frames=True)
    
    # Extract main content frame
    main_frame = tree.select_one("#main_content_frame")
    if not main_frame:
        raise ValueError("Missing primary frameset target")
    
    # Convert deprecated attributes to CSS
    main_frame.align = main_frame.get("align")
    main_frame.style = f"text-align: {main_frame.align}"
    
    return str(main_frame)

# Usage
# processed = flatten_frameset(warc_record.content)
[RESOLVER] Detected frameset: rows="120,*" [RESOLVER] Converting ALIGN="CENTER" → text-align: center [RESOLVER] Flattened 3 nested tables into grid layout [SUCCESS] DOM ready for modern rendering

3. Extracting GIF89a & MIDI Metadata

Early web assets often contained embedded control blocks. The asset extractor isolates animation frames and sequence data.

JAVASCRIPT
import { AssetExtractor } from '@1990-archive/decoder';

async function decodeAnimatedGIF(buffer) {
  const extractor = new AssetExtractor('gif89a');
  const metadata = await extractor.analyze(buffer);

  if (metadata.isAnimated) {
    console.log(`Frame count: ${metadata.frameCount}`);
    console.log(`Loop count: ${metadata.loopCount}`);
    
    // Extract first frame as PNG for archival
    const firstFrame = await extractor.decodeFrame(0, { format: 'png' });
    return firstFrame.buffer;
  }
  return null;
}

// MIDI sequence parser example
// const tracks = await AssetExtractor.parseMIDI(midiBuffer);
[DECODER] Signature: GIF89a [DECODER] Dimensions: 400x300 [DECODER] Frame count: 12 [DECODER] Loop count: 0 (infinite) [DECODER] Palette: 256 colors [SUCCESS] Frame 0 extracted (24-bit PNG)

4. CLI: Bulk Archive Export

Use the official CLI tool to download WARC bundles, convert them to static HTML, and verify cryptographic signatures.

BASH
# Initialize project and download seed list
1990-archive init my-project
1990-archive crawl --url-list seeds_1997.txt --output ./captures

# Convert WARC bundles to renderable static HTML
1990-archive convert ./captures/*.warc --format html5 --flatten-frames

# Verify archive integrity using SHA-256 manifests
1990-archive verify ./captures --manifest manifests.json

# Generate diff report against Wayback baseline
1990-archive diff ./captures --baseline wayback:1998 --output report.md
[INIT] Created ./my-archive/.config/arc.json [FETCH] Resolving 142 URLs from seed list [CONVERT] Processing archive-01.warc (4.2MB) [CONVERT] Processing archive-02.warc (3.8MB) [VERIFY] 2/2 bundles valid (SHA-256 matched) [DIFF] 12 URLs diverged from baseline [COMPLETE] Export finished in 4.2s