GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - saveweb/gowarc: gowarc, but saveweb's (upstream: https://github.com/internetarchive/gowarc)

BranchesTags
Open more actions menu

Latest commit

 

History

350 Commits
350 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
cmd
cmd
 
 
pkg/spooledtempfile
pkg/spooledtempfile
 
 
testdata
testdata
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
body_readers.go
body_readers.go
 
 
capture_recorder.go
capture_recorder.go
 
 
capture_recorder_test.go
capture_recorder_test.go
 
 
client.go
client.go
 
 
client_test.go
client_test.go
 
 
customTLSSpec.go
customTLSSpec.go
 
 
dedupe.go
dedupe.go
 
 
dialer.go
dialer.go
 
 
dialer_test.go
dialer_test.go
 
 
digest.go
digest.go
 
 
digest_test.go
digest_test.go
 
 
dns.go
dns.go
 
 
dns_test.go
dns_test.go
 
 
exchange.go
exchange.go
 
 
exchange_test.go
exchange_test.go
 
 
file.go
file.go
 
 
file_test.go
file_test.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
gzip_interface.go
gzip_interface.go
 
 
gzip_klauspost_impl.go
gzip_klauspost_impl.go
 
 
gzip_standard_impl.go
gzip_standard_impl.go
 
 
header.go
header.go
 
 
header_test.go
header_test.go
 
 
http2client.go
http2client.go
 
 
keepalive_test.go
keepalive_test.go
 
 
main_test.go
main_test.go
 
 
protocol.go
protocol.go
 
 
protocol_test.go
protocol_test.go
 
 
random_local_ip.go
random_local_ip.go
 
 
random_local_ip_test.go
random_local_ip_test.go
 
 
read.go
read.go
 
 
read_test.go
read_test.go
 
 
record.go
record.go
 
 
record_pipeline.go
record_pipeline.go
 
 
response_body.go
response_body.go
 
 
smoke_test.go
smoke_test.go
 
 
transport.go
transport.go
 
 
utils.go
utils.go
 
 
utils_test.go
utils_test.go
 
 
uuid.go
uuid.go
 
 
waitgroup.go
waitgroup.go
 
 
warc.go
warc.go
 
 
warc_test.go
warc_test.go
 
 
write.go
write.go
 
 
write_zstd_e2e_test.go
write_zstd_e2e_test.go
 
 
zstd_writer.go
zstd_writer.go
 
 

Repository files navigation

warc

GoDoc Go Report Card

A Go library for reading and writing WARC files, with advanced features for web archiving.

Features

  • Read and write WARC files with support for multiple compression formats (GZIP, ZSTD)
  • HTTP client with built-in WARC recording capabilities
  • Content deduplication (local URL-agnostic and CDX-based)
  • Configurable file rotation and size limits
  • DNS caching and custom DNS resolution (with DNS archiving)
  • Custom TLS configurations
  • Random local IP assignment for distributed crawling (including Linux kernel AnyIP feature)
  • Smart memory management with disk spooling options
  • IPv4/IPv6 support with configurable preferences

Installation

go get github.com/internetarchive/gowarc

Usage

This library's biggest feature is to provide a standard HTTP client through which you can execute requests that will be recorded automatically to WARC files. It's the basis of Zeno.

HTTP Client with WARC Recording

package main

import (
	"context"
	"io"

	http "github.com/saveweb/fhttp"
	warc "github.com/saveweb/gowarc"
)

func main() {
	// Configure WARC settings
	rotator := warc.NewRotatorSettings("crawler.example.com")
	rotator.Prefix = "WEB"
	rotator.OutputDirectory = "./warcs"
	// WARC record IDs use UUIDv7 by default. Use UUIDv4 when compatibility
	// with a consumer that requires random UUIDs is needed.
	// rotator.RecordIDVersion = warc.UUIDv4

	// Configure HTTP client settings
	clientSettings := warc.HTTPClientSettings{
		RotatorSettings: rotator,
		TempDir:         "./temp",
		EnableHTTP2:     true,
		// Keepalive is enabled by default. Set DisableKeepAlives only when
		// connection reuse is intentionally unwanted.
	}

	// Create HTTP client
	client, err := warc.NewWARCWritingHTTPClient(clientSettings)
	if err != nil {
		panic(err)
	}

	req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://archive.org", nil)
	if err != nil {
		panic(err)
	}
	exchange, startErr := client.Start(req)
	if exchange == nil {
		panic(startErr)
	}
	// Releases the capture on every early-return path. Once Commit succeeds,
	// this deferred Discard cannot change the decision.
	defer exchange.Discard(context.Background())
	if startErr != nil {
		// Commit includes the Start error in its complete result. Do not join
		// startErr again, or the same transport failure will be printed twice.
		_, err := exchange.Commit(context.Background())
		panic(err)
	}
	// Process response
	_, _ = io.Copy(io.Discard, exchange.Response.Body)
	_ = exchange.Response.Body.Close()
	// Keep the exchange and wait until its records reach the WARC writer.
	if _, err := exchange.Commit(context.Background()); err != nil {
		panic(err)
	}
	finalized, err := client.Shutdown(context.Background())
	if err != nil {
		panic(err)
	}
	_ = finalized.FinalizedFiles
}

HTTP/1 captures contain the plaintext HTTP/1 wire bytes seen by the transport. HTTP/2 and HTTP/3 captures are deterministic application/http serializations of the actual stream headers, body data, and trailers. Closing a response body early performs a bounded drain; if the message boundary cannot be reached, Exchange.Commit reports a truncated attempt. To reject a capture after inspecting its response, call Exchange.Discard; it closes any unread response body and releases the captured temporary data.

HTTP exchanges are written in request-then-response order by default. Set rotator.UseInternetArchiveRecordOrder = true for IA-compatible response-then-request order.

CLI Tools

In addition to the Go library, gowarc provides several command-line utilities for working with WARC files:

Installation

Pre-built releases are available on the GitHub releases page.

# Install from source
go install github.com/internetarchive/gowarc/cmd/warc@latest

# Or build locally
cd cmd/warc/
go build -o warc

Available Commands

warc extract

Extract files and content from WARC archives with filtering options.

# Extract all files from WARC archives
warc extract file1.warc.gz file2.warc.gz

# Extract only specific content types
warc extract --content-type "text/html" --content-type "image/jpeg" archive.warc.gz

# Extract to specific directory with multiple threads  
warc extract --output ./extracted --threads 4 *.warc.gz

# Sort extracted files by host
warc extract --host-sort archive.warc.gz

warc mend

Repair and close incomplete gzip-compressed WARC files that were left with .open suffix during crawling.

# Dry run to see what would be fixed
warc mend --dry-run *.warc.gz.open

# Fix files with confirmation prompts  
warc mend corrupted.warc.gz.open

# Auto-fix without prompts
warc mend --yes *.warc.gz.open

# Force verification of any gzip WARC files (not just .open)
warc mend --force --dry-run archive.warc.gz

Features:

  • By default, only processes .open files; use --force to verify any gzip WARC files
  • Verifies gzip format using magic bytes, not just file extension
  • Detects and removes trailing garbage bytes
  • Truncates at corruption points while preserving maximum valid data
  • Removes .open suffix to "close" files when present
  • Provides comprehensive statistics on repairs performed
  • Memory-efficient streaming for large files

See cmd/warc/mend/README.md for detailed documentation.

warc verify

Validate the integrity and structure of WARC files.

# Verify single file
warc verify archive.warc.gz

# Verify multiple files with progress
warc verify -v *.warc.gz

# JSON output for automation
warc verify --json archive.warc.gz

warc completion

Generate shell completion scripts for bash, zsh, fish, or PowerShell.

# Bash completion
warc completion bash > /etc/bash_completion.d/warc

# Zsh completion
warc completion zsh > ~/.zsh/completions/_warc

# Fish completion
warc completion fish > ~/.config/fish/completions/warc.fish

# PowerShell completion
warc completion powershell > warc.ps1

Global Flags

All commands support these global options:

  • -v, --verbose - Enable verbose/debug logging
  • --json - Output logs in JSON format for structured processing
  • -h, --help - Show help for any command

Build tags

  • standard_gzip: Use the standard library gzip implementation instead of the faster one from klauspost
  • klauspost_gzip: Use the faster gzip implementation from klauspost (default, you don't need to specify it)

License

This module is released under CC0 license. You can find a copy of the CC0 License in the LICENSE file.

About

gowarc, but saveweb's (upstream: https://github.com/internetarchive/gowarc)

Resources

Readme
CC0-1.0 license
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.