### Build and install Siegfried from source
Source: https://github.com/richardlehane/siegfried/wiki/Getting-started
Use Go to build and install the sf and roy binaries.
```bash
go install github.com/richardlehane/siegfried/cmd/sf@latest
go install github.com/richardlehane/siegfried/cmd/roy@latest
```
--------------------------------
### Install Siegfried on Ubuntu/Debian
Source: https://github.com/richardlehane/siegfried/wiki/Getting-started
Add the repository and install Siegfried using apt.
```bash
curl -sL "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x20F802FE798E6857" | gpg --dearmor | sudo tee /usr/share/keyrings/siegfried-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/siegfried-archive-keyring.gpg] https://www.itforarchivists.com/ buster main" | sudo tee -a /etc/apt/sources.list.d/siegfried.list
sudo apt-get update && sudo apt-get install siegfried
```
--------------------------------
### Start Server with Logging
Source: https://context7.com/richardlehane/siegfried/llms.txt
Starts the Siegfried HTTP server with progress and error logging enabled, listening on localhost:5138.
```bash
sf -log progress,error -serve localhost:5138
```
--------------------------------
### Install Siegfried with Go
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Install Siegfried using the Go toolchain. Ensure your Go environment is set up correctly.
```bash
go install github.com/richardlehane/siegfried/cmd/sf@latest
sf -update
```
--------------------------------
### Siegfried WASM - Running the Example Locally
Source: https://github.com/richardlehane/siegfried/blob/main/wasm/README.md
Instructions and a Go script to set up a local server for running the Siegfried WASM example.
```Go
package main
import (
"flag"
"log"
"net/http"
)
func main() {
port := flag.String("p", "8100", "port to serve on")
directory := flag.String("d", ".", "the directory of static file to host")
flag.Parse()
http.Handle("/", http.FileServer(http.Dir(*directory)))
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
log.Fatal(http.ListenAndServe(":"+*port, nil))
}
```
--------------------------------
### Install Siegfried on FreeBSD
Source: https://github.com/richardlehane/siegfried/wiki/Getting-started
Install Siegfried using the pkg package manager.
```bash
pkg install siegfried
```
--------------------------------
### Install Siegfried on Arch Linux
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Build and install Siegfried from the AUR using git and makepkg.
```bash
git clone https://aur.archlinux.org/siegfried.git
cd siegfried
makepkg -si
```
--------------------------------
### Start Server with Default Settings
Source: https://context7.com/richardlehane/siegfried/llms.txt
Starts the Siegfried HTTP server with default settings, including no recursion, zip support, MD5 hashing, and listening on localhost:5138.
```bash
sf -nr -z -hash md5 -serve localhost:5138
```
--------------------------------
### Create a Local Development Server
Source: https://github.com/richardlehane/siegfried/blob/main/wasm/README.md
A simple Go-based HTTP server to host the WASM example files locally.
```go
package main
import (
"flag"
"log"
"net/http"
)
func main() {
port := flag.String("p", "8100", "port to serve on")
directory := flag.String("d", ".", "the directory of static file to host")
flag.Parse()
http.Handle("/", http.FileServer(http.Dir(*directory)))
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
log.Fatal(http.ListenAndServe(":"+*port, nil))
}
```
--------------------------------
### Start Server on Localhost Port 5138
Source: https://context7.com/richardlehane/siegfried/llms.txt
Starts the Siegfried HTTP server on localhost, listening on port 5138.
```bash
sf -serve localhost:5138
```
--------------------------------
### Install Siegfried on Windows
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Download a pre-built binary for Windows from the releases page and add it to your system path.
```bash
sf -update
```
--------------------------------
### Wikidata Harvest Output Example
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
Example YAML output showing a file match with a German format translation.
```yaml
filename : 'shortcut.lnk'
filesize : 8
modified : 2021-04-18T17:07:20+02:00
errors :
matches :
- ns : 'wikidata'
id : 'Q1109779'
format : 'Dateiverknüpfung'
URI : 'http://www.wikidata.org/entity/Q1109779'
mime : 'application/x-ms-shortcut'
basis : 'byte match at 0, 8'
source : 'Wikidata reference is empty'
warning : 'extension mismatch'
```
--------------------------------
### GET /identify
Source: https://github.com/richardlehane/siegfried/wiki/Using-the-siegfried-server
Identify files or directories by providing their path in the URL. Default parameters can be set using sf flags when starting the server.
```APIDOC
## GET /identify
### Description
Identify files or directories by providing their path in the URL. This endpoint supports various query parameters to control the identification process and output format.
### Method
GET
### Endpoint
`/identify/percent_encoded_file_or_folder_name`
### Query Parameters
- **base64** (boolean) - Optional - Use URL-safe base64 encoding for the file or folder name when set to `true`.
- **nr** (boolean) - Optional - Stop sub-directory recursion when a directory path is given and set to `true`.
- **format** (string) - Optional - Select the output format (e.g., `csv`, `yaml`, `json`, `droid`). Defaults to `yaml`. HTTP content negotiation can also be used.
- **hash** (string) - Optional - Calculate file checksum. Supported values: `md5`, `sha1`, `sha256`, `sha512`, `crc`.
- **z** (boolean) - Optional - Scan archive formats (zip, tar, gzip, warc, arc) when set to `true`. Defaults to `false`.
- **sig** (string) - Optional - Load a specific signature file. Defaults to `default.sig`.
### Request Example
`http://localhost:5138/identify/c%3A%2FUsers%2Frichardl%2FMy%20Documents%2Fhello%20world.docx?format=json`
### Response
#### Success Response (200)
- **(response body)** - The identification results in the specified format.
#### Response Example
```json
{
"example": "response body"
}
```
```
--------------------------------
### Start Siegfried Server
Source: https://github.com/richardlehane/siegfried/wiki/Using-the-siegfried-server
Run the siegfried server with a specified hostname and port. Default settings for identification parameters can also be applied.
```bash
sf -serve localhost:5138
```
```bash
sf -nr -z -hash md5 -sig pronom-tika.sig -log p,w,e -serve localhost:5138
```
--------------------------------
### Configure Logging Output
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Examples of using the -log flag to monitor scan progress and filter output.
```bash
sf -log progress -csv DIR > my_results.csv
```
--------------------------------
### HTTP Content Negotiation for Format via GET
Source: https://context7.com/richardlehane/siegfried/llms.txt
Identifies a file using an HTTP GET request and uses the 'Accept' header for content negotiation to request JSON output.
```bash
curl -H "Accept: application/json" "http://localhost:5138/identify/path%2Fto%2Ffile.pdf"
```
--------------------------------
### Install Siegfried via Homebrew
Source: https://github.com/richardlehane/siegfried/wiki/Getting-started
Install Siegfried on macOS or Linux using the Homebrew package manager.
```bash
brew install richardlehane/digipres/siegfried
```
--------------------------------
### Siegfried WASM - Installation Script
Source: https://github.com/richardlehane/siegfried/blob/main/wasm/README.md
This script demonstrates how to include and load the Siegfried WASM module in a web page.
```HTML
```
--------------------------------
### Siegfried Identification Output Example
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
Example of the YAML output generated by Siegfried after identifying a file using a Wikidata-based signature.
```yaml
---
siegfried : 1.9.2
scandate : 2022-09-07T12:30:19+02:00
signature : default.sig
created : 2022-09-07T12:30:16+02:00
identifiers :
- name : 'wikidata'
details : 'wikidata-definitions-3.0.0 (2022-09-07)'
---
filename : 'raster-example-skeleton'
filesize : 10
modified : 2022-09-07T12:29:20+02:00
errors :
matches :
- ns : 'wikidata'
id : 'Q1143961'
format : 'JBIG2'
URI : 'http://www.wikidata.org/entity/Q1143961'
permalink : 'https://www.wikidata.org/w/api.php/w/index.php?oldid=1526516378&title=Q1143961'
mime :
basis : 'byte match at 0, 8 (Gary Kessler''s File Signature Table (source date: 2017-08-08))'
warning : 'extension mismatch'
```
--------------------------------
### GET /update
Source: https://context7.com/richardlehane/siegfried/llms.txt
Hot-reload signature files on a running server.
```APIDOC
## GET /update
### Description
Triggers a reload of signature files on the running server.
### Method
GET
### Endpoint
/update or /update/{identifier}
### Parameters
#### Path Parameters
- **identifier** (string) - Optional - Specific identifier to update (e.g., wikidata, loc).
```
--------------------------------
### GET /identify/{path}
Source: https://context7.com/richardlehane/siegfried/llms.txt
Identify files on the server filesystem using a percent-encoded path.
```APIDOC
## GET /identify/{path}
### Description
Identify files located on the server's filesystem.
### Method
GET
### Endpoint
/identify/{path}
### Parameters
#### Path Parameters
- **path** (string) - Required - The percent-encoded path to the file or directory on the server.
#### Query Parameters
- **format** (string) - Optional - Output format (e.g., json, csv).
- **hash** (string) - Optional - Checksum algorithm (e.g., md5, sha256).
- **nr** (boolean) - Optional - If true, scan directory without recursion.
- **z** (boolean) - Optional - If true, scan archives within directory.
- **base64** (boolean) - Optional - If true, indicates the path is base64 encoded.
- **sig** (string) - Optional - Name of the specific signature file to use.
### Response
#### Success Response (200)
- **results** (object/array) - Identification results based on requested format.
```
--------------------------------
### Wikidata Linting Messages Example
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
JSON snippet showing specific warning and error messages generated during the build process.
```json
"AllLintingMessages": [
"Linting: WARNING no encoding: URI: http://www.wikidata.org/entity/Q4839791 Critical: false",
"Linting: WARNING no provenance: URI: http://www.wikidata.org/entity/Q4839791 Critical: false",
"Linting: WARNING no provenance date: URI: http://www.wikidata.org/entity/Q98843338 Critical: false",
"Linting: ERROR bad heuristic: URI: http://www.wikidata.org/entity/Q1109779 Critical: true",
"Linting: ERROR blank node returned for offset: URI: http://www.wikidata.org/entity/Q26546575 Critical: false",
"Linting: WARNING no relativity: URI: http://www.wikidata.org/entity/Q939636 Critical: false",
],
```
--------------------------------
### Use Specific Signature File via HTTP GET
Source: https://context7.com/richardlehane/siegfried/llms.txt
Identifies a file using an HTTP GET request, specifying a custom signature file ('loc.sig') for identification.
```bash
curl "http://localhost:5138/identify/path%2Fto%2Ffile.pdf?sig=loc.sig"
```
--------------------------------
### Roy Harvest Command for Custom Wikibase
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
Execute this command to harvest data from your custom Wikibase endpoint. Replace the example URLs with your specific Wikibase instance details.
```bash
./roy harvest \
-wikidata \
-wikidataendpoint http://wikibase.example.com:8834/proxy/wdqs/bigdata/namespace/wdq/sparql? \
-wikibaseurl http://wikibase.example.com/
```
--------------------------------
### Scan files from a list piped to stdin (Windows)
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Use the -f flag with a hyphen to read a newline-separated list of files and directories from stdin. This example uses dir on Windows.
```bash
dir /b /s *.doc | sf -f -
```
--------------------------------
### Scan files from a list piped to stdin (Linux/macOS)
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Use the -f flag with a hyphen to read a newline-separated list of files and directories from stdin. This example uses find on Linux/macOS.
```bash
find */*.doc | sf -f -
```
--------------------------------
### Get absolute file paths in results
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Use shell environment variables to pass absolute paths to sf, ensuring results contain full file paths.
```shell
sf %cd%\docs [on Windows]
```
```shell
sf $PWD/docs [on unix]
```
--------------------------------
### Access Help Documentation
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Display available command-line options.
```bash
sf -help
```
--------------------------------
### Example Roy Inspect Output
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
This YAML output shows detailed information about a signature, including its name, MIME types, sources, Wikidata QID, globs, signature byte sequences, and superior identifiers. It is generated by the 'roy inspect' command.
```yaml
FORMAT INFO: NAME: 'FLAC'
MIMETYPE: 'AUDIO/X-OGG; AUDIO/X-FLAC; AUDIO/FLAC'
SOURCES: 'GARY KESSLER\'S FILE SIGNATURE TABLE (SOURCE DATE: 2017-08-08) PRONOM (OFFICIAL (FMT/279))'
QID: (Q27881556)
globs: *.flac, *.oga
sigs: (B:0 seq "fLaC\x00\x00\x00\"")
(B:0..4 seq "fLaC\x00\x00\x00\")
superiors: none
```
--------------------------------
### Version and Home Directory Options
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Display version information or specify a custom home directory for signatures.
```bash
sf -v | -version
sf -home c:\junk -sig custom.sig file.ext
```
--------------------------------
### Hashing and Signature File Options
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Calculate file hashes or use custom signature files.
```bash
sf -hash md5 file.ext | *.ext | DIR
sf -sig custom.sig *.ext | DIR
```
--------------------------------
### Replay and Configuration Options
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Replay previous results or save/load default command-line flags.
```bash
sf -replay -log u -csv results.yaml
sf -setconf -multi 32 -hash sha1
sf -setconf -serve :5138 -conf srv.conf
```
--------------------------------
### Identify File with JSON Output via HTTP GET
Source: https://context7.com/richardlehane/siegfried/llms.txt
Identifies a file using an HTTP GET request and requests the output in JSON format.
```bash
curl "http://localhost:5138/identify/path%2Fto%2Ffile.docx?format=json"
```
--------------------------------
### Basic File Identification using Siegfried Go Library
Source: https://context7.com/richardlehane/siegfried/llms.txt
Demonstrates basic file identification using the Siegfried Go library. Loads a signature file, opens a target file, and processes the identification results.
```go
package main
import (
"fmt"
"log"
"os"
"github.com/richardlehane/siegfried"
)
func main() {
// Load signature file
s, err := siegfried.Load("default.sig")
if err != nil {
log.Fatal(err)
}
// Open file to identify
f, err := os.Open("document.pdf")
if err != nil {
log.Fatal(err)
}
defer f.Close()
// Identify the file (reader, filename, MIME hint)
ids, err := s.Identify(f, "document.pdf", "")
if err != nil {
log.Fatal(err)
}
// Process identification results
for _, id := range ids {
fmt.Printf("Format: %s\n", id)
// Access individual field values
values := id.Values()
fmt.Printf(" Namespace: %s\n", values[0])
fmt.Printf(" ID: %s\n", values[1])
fmt.Printf(" Format: %s\n", values[2])
fmt.Printf(" Version: %s\n", values[3])
fmt.Printf(" MIME: %s\n", values[4])
}
}
```
--------------------------------
### Identify a File via HTTP GET
Source: https://context7.com/richardlehane/siegfried/llms.txt
Identifies a specific file using an HTTP GET request to the Siegfried server. The file path must be percent-encoded.
```bash
curl "http://localhost:5138/identify/c%3A%2FUsers%2Fuser%2Fdocument.pdf"
```
--------------------------------
### Inspect PRONOM release notes
Source: https://github.com/richardlehane/siegfried/blob/main/CHANGELOG.md
View a summary of a PRONOM release-notes.xml file.
```bash
roy inspect releases
```
--------------------------------
### Scan Directory without Recursion via HTTP GET
Source: https://context7.com/richardlehane/siegfried/llms.txt
Scans a directory using an HTTP GET request without recursing into subdirectories. 'nr=true' disables recursion.
```bash
curl "http://localhost:5138/identify/path%2Fto%2Fdirectory?nr=true"
```
--------------------------------
### Basic Command Line Usage
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Scan a single file, multiple files, or a directory using default settings.
```bash
sf file.ext
sf *.ext
sf DIR
```
--------------------------------
### Identify File with Checksum via HTTP GET
Source: https://context7.com/richardlehane/siegfried/llms.txt
Identifies a file using an HTTP GET request, specifying the hash algorithm (MD5) and requesting JSON output.
```bash
curl "http://localhost:5138/identify/path%2Fto%2Ffile.pdf?hash=md5&format=json"
```
--------------------------------
### Manage signature files
Source: https://context7.com/richardlehane/siegfried/llms.txt
Use custom signature files or update existing ones from various sources.
```bash
# Use a custom signature file
sf -sig custom.sig /path/to/documents
# Use a custom home directory for signatures
sf -home /custom/siegfried/home -sig mysig.sig /path/to/documents
# Update to the latest PRONOM signatures
sf -update
# Download non-PRONOM signature files
sf -update loc # Library of Congress
sf -update tika # Apache Tika
sf -update freedesktop # freedesktop.org MIME-info
sf -update deluxe # Combined PRONOM + Tika + LOC
sf -update archivematica # Archivematica-specific signatures
# Update and save to a specific signature file
sf -sig loc.sig -update loc
```
--------------------------------
### Scan a list of files and directories
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Provide multiple files and directories as arguments to scan them all in a single command.
```bash
sf myfile1.doc mydir myfile3.txt
```
--------------------------------
### Use Base64 Encoding for Complex Paths via HTTP GET
Source: https://context7.com/richardlehane/siegfried/llms.txt
Identifies a file using an HTTP GET request where the path is encoded in Base64. 'base64=true' indicates Base64 encoding.
```bash
curl "http://localhost:5138/identify/$(echo -n '/path/to/file.pdf' | base64)?base64=true"
```
--------------------------------
### Scan Archives within Directory via HTTP GET
Source: https://context7.com/richardlehane/siegfried/llms.txt
Scans archives within a directory using an HTTP GET request, enabling zip support ('z=true') and requesting CSV output.
```bash
curl "http://localhost:5138/identify/path%2Fto%2Farchives?z=true&format=csv"
```
--------------------------------
### Load Named Configuration
Source: https://context7.com/richardlehane/siegfried/llms.txt
Loads a previously saved named configuration file.
```bash
sf -conf server.conf
```
--------------------------------
### Identify Files with Buffer Pooling in Go
Source: https://context7.com/richardlehane/siegfried/llms.txt
Utilize a reusable buffer pool for efficient identification of multiple files. Ensure the signature file is loaded before processing.
```go
package main
import (
"fmt"
"log"
"os"
"github.com/richardlehane/siegfried"
)
func main() {
s, err := siegfried.Load("default.sig")
if err != nil {
log.Fatal(err)
}
files := []string{"doc1.pdf", "doc2.docx", "image.jpg"}
for _, filename := range files {
f, err := os.Open(filename)
if err != nil {
log.Printf("Error opening %s: %v", filename, err)
continue
}
// Get a reusable buffer from the pool
buffer, err := s.Buffer(f)
// Identify using the buffer
ids, err := s.IdentifyBuffer(buffer, err, filename, "")
// Return buffer to the pool
s.Put(buffer)
f.Close()
if err != nil {
log.Printf("Error identifying %s: %v", filename, err)
continue
}
fmt.Printf("File: %s\n", filename)
for _, id := range ids {
// Get labeled field values
for _, label := range s.Label(id) {
fmt.Printf(" %s: %s\n", label[0], label[1])
}
}
}
}
```
--------------------------------
### Build and Add Identifiers with roy
Source: https://github.com/richardlehane/siegfried/wiki/Building-a-signature-file-with-ROY
Use roy build to initialize a signature file and roy add to append additional identifiers to an existing file.
```bash
roy build -name latest -nocontainer history.sig
```
```bash
roy add -name "version 10" -droid DroidSignatureFile_Version10.xml -noreports -nocontainer history.sig
```
--------------------------------
### View Chart of Formats from Results
Source: https://context7.com/richardlehane/siegfried/llms.txt
Replays scan results and displays a chart of formats, along with standard output.
```bash
sf -replay -log chart,stdout results.yaml
```
--------------------------------
### Build Signature Files with Roy
Source: https://context7.com/richardlehane/siegfried/llms.txt
Use the roy build command to generate signature files with various configurations, including format limits, extensions, and source types.
```bash
# Build default PRONOM signature file
roy build
# Build with custom name
roy build -name my-pronom my-signatures.sig
# Build with BOF/EOF offset limits (faster scanning, less accurate)
roy build -bof 65536 -eof 32768 fast.sig
# Build without container signatures
roy build -nocontainer simple.sig
# Build MIME-info signature file (Apache Tika)
roy build -mi tika-mimetypes.xml tika.sig
# Build MIME-info signature file (freedesktop.org)
roy build -mi freedesktop freedesktop.sig
# Build Library of Congress FDD signature file
roy build -loc loc.sig
# Build LOC without PRONOM cross-references
roy build -loc -nopronom loc-only.sig
# Build Wikidata signature file
roy harvest -wikidata # First harvest definitions
roy build -wikidata wikidata.sig
# Limit signature to specific formats
roy build -limit fmt/14,fmt/15,fmt/16 pdf-only.sig
# Limit using format sets
roy build -limit @pdf pdf-formats.sig
# Exclude specific formats
roy build -exclude @pdfa,@pdfx standard-pdf.sig
# Extend with custom DROID-format signatures
roy build -extend custom-signatures.xml extended.sig
# Extend with custom container signatures
roy build -extend custom-sigs.xml -extendc custom-container.xml extended.sig
# Build without byte signatures (extension/container only)
roy build -nobyte extension-only.sig
# Build without reports (DROID file only, faster)
roy build -noreports quick.sig
```
--------------------------------
### Roy Build Command with Wikidata Flag
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
Run this command after harvesting and configuring your `wikibase.json` to build signature definitions from your custom Wikibase data.
```bash
./roy build -wikidata
```
--------------------------------
### Create Custom Signature Files in Go
Source: https://context7.com/richardlehane/siegfried/llms.txt
Programmatically configure and save custom signature files using the Siegfried API. Requires importing the pronom and config packages.
```go
package main
import (
"log"
"github.com/richardlehane/siegfried"
"github.com/richardlehane/siegfried/pkg/pronom"
"github.com/richardlehane/siegfried/pkg/config"
)
func main() {
// Create a new Siegfried instance
s := siegfried.New()
// Configure options for the identifier
opts := []config.Option{
config.SetName("custom-pronom"),
config.SetDetails("Custom PRONOM identifier with BOF limit"),
config.SetBOF(65536), // Limit beginning-of-file scanning to 64KB
}
// Create a new PRONOM identifier with options
p, err := pronom.New(opts...)
if err != nil {
log.Fatal(err)
}
// Add the identifier to Siegfried
err = s.Add(p)
if err != nil {
log.Fatal(err)
}
// Save the signature file
err = s.Save("custom.sig")
if err != nil {
log.Fatal(err)
}
log.Println("Signature file created: custom.sig")
}
```
--------------------------------
### Build Custom Signature Files
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Create a signature file limited to specific formats using the roy tool.
```bash
roy build -limit @pdf -name pdf_only pdf.sig
```
--------------------------------
### Save and Load Scan Configurations
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Commands for managing default and named configuration files for the sf tool.
```bash
sf -setconf -multi 32 -hash sha1 -csv
```
```bash
sf -setconf -serve :5138 -z -hash md5 -conf server.conf
```
```bash
sf -conf server.conf
```
--------------------------------
### GET Request for File Identification
Source: https://github.com/richardlehane/siegfried/wiki/Using-the-siegfried-server
Identify files or directories by providing their path in the URL. Optional parameters can control recursion, output format, hashing, archive scanning, and signature files.
```http
GET /identify/percent_encoded_file_or_folder_name?base64=false&nr=true&format=yaml&hash=md5&z=true&sig=default.sig
```
```http
http://localhost:5138/identify/c%3A%2FUsers%2Frichardl%2FMy%20Documents%2Fhello%20world.docx?format=json
```
--------------------------------
### Output Format Options
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Specify the output format as CSV, JSON, or DROID CSV.
```bash
sf -csv file.ext | *.ext | DIR
sf -json file.ext | *.ext | DIR
sf -droid file.ext | *.ext | DIR
```
--------------------------------
### TrID Example SPARQL Query for Wikidata
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
This SPARQL query retrieves file format records from Wikidata, specifically filtering for those with TrID signatures. It includes optional fields for detailed information and uses a specific reference for TrID.
```sparql
# Return all file format records from Wikidata.
#
# Custom query example:
#
# All formats must have a signature.
# All signatures must come from the TrID Q41799265 reference.
#
# NB. Keep in mind all optional fields as they increase the
# number of fields where schemas aren't consistent across entries.
#
SELECT DISTINCT ?uri ?uriLabel ?puid ?extension ?mimetype ?encoding ?referenceLabel ?date ?relativity ?offset ?sig WHERE {
?uri (wdt:P31/(wdt:P279*)) wd:Q235557.
OPTIONAL { ?uri wdt:P2748 ?puid. }
OPTIONAL { ?uri wdt:P1195 ?extension. }
OPTIONAL { ?uri wdt:P1163 ?mimetype. }
?uri p:P4152 ?object.
?object ps:P4152 ?sig;
prov:wasDerivedFrom ?provenance.
?provenance pr:P248 wd:Q41799265, ?reference. # <-- modified to return TrID only, and TrID's reference label.
OPTIONAL { ?provenance pr:P813 ?date. }
OPTIONAL { ?object pq:P3294 ?encoding. }
OPTIONAL { ?object pq:P2210 ?relativity. }
OPTIONAL { ?object pq:P4153 ?offset. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en". }
}
ORDER BY (?uri)
```
--------------------------------
### Generate Default Format Sets
Source: https://context7.com/richardlehane/siegfried/llms.txt
Generates the default format sets from PRONOM data. This is the basic command for initializing format sets.
```bash
roy sets
```
--------------------------------
### Parallel Scanning and Logging Options
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Configure parallel file scanning and detailed logging.
```bash
sf -multi 256 DIR
sf -log [comma-sep opts] file.ext
sf -log e,w file.ext | *.ext | DIR
sf -log u,o file.ext | *.ext | DIR
sf -log d,s file.ext | *.ext | DIR
sf -log p,t DIR > results.yaml
sf -log fmt/1,c DIR > results.yaml
```
--------------------------------
### Example Siegfried Scan Output
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
This YAML output details a Siegfried scan result for 'img.bmp'. It includes metadata about the scan, the file, and any identified matches, such as the 'Windows Bitmap, version 4' format linked to Wikidata QID 'Q27596325'. It also indicates the basis for the match, like extension and byte sequence.
```yaml
---
siegfried : 1.9.1
scandate : 2020-11-15T22:24:56-05:00
signature : default.sig
created : 2020-11-15T22:24:35-05:00
identifiers :
- name : 'wikidata'
details : 'wikidata-definitions-1.0.0 (2020-11-15)'
---
filename : 'img.bmp'
filesize : 35
modified : 2020-11-15T22:26:09-05:00
errors :
matches :
- ns : 'wikidata'
id : 'Q27596325'
format : 'Windows Bitmap, version 4'
URI : 'http://www.wikidata.org/entity/Q27596325'
mime :
basis : 'extension match bmp; byte match at 0, 35'
source : 'PRONOM (Wikidata) (source date: 2017-08-08)'
warning :
software :
```
--------------------------------
### Pipe unknown files to external tools
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Use sf to identify unknown files and pipe the list to file or Tika for further analysis.
```shell
sf -log unknown,stdout DIR | xargs -d '\n' file
```
```shell
sf -log unknown,stdout DIR | xargs -d '\n' -n 1 java -jar tika-app.jar -d
```
--------------------------------
### Manage format sets
Source: https://github.com/richardlehane/siegfried/blob/main/CHANGELOG.md
Use roy sets to generate or list format set definitions.
```bash
roy sets
```
```bash
roy sets -changes
```
```bash
roy sets -list @set1,@set2
```
--------------------------------
### Build and inspect with sets
Source: https://github.com/richardlehane/siegfried/blob/main/CHANGELOG.md
Use sets to filter PUIDs by extension during build and inspection operations.
```bash
roy build -limit @.doc,@.docx
```
```bash
roy inspect @.txt
```
```bash
sf -log @.pdf,o DIR
```
--------------------------------
### Inspect Signature Files
Source: https://github.com/richardlehane/siegfried/wiki/Building-a-signature-file-with-ROY
Use the inspect command to view the contents of a generated signature file.
```bash
roy inspect
```
--------------------------------
### Build Siegfried WASM
Source: https://github.com/richardlehane/siegfried/blob/main/wasm/README.md
Command to compile the Siegfried Go package into a WebAssembly binary.
```bash
GOOS=js GOARCH=wasm go build -o sf.wasm github.com/richardlehane/siegfried/wasm
```
--------------------------------
### Extend signature file
Source: https://github.com/richardlehane/siegfried/wiki/Building-a-signature-file-with-ROY
Use this command to incorporate custom definitions into existing signature files.
```cli
roy build -extend /path/to/custom-signature.xml
```
--------------------------------
### Replay scan results from files
Source: https://github.com/richardlehane/siegfried/blob/main/CHANGELOG.md
Use the -replay flag to process previously generated results files.
```bash
sf -replay -f list-of-results.txt
```
```bash
sf -replay -csv results.yaml
```
```bash
sf -replay -log unknown,chart,stdout results1.yaml results2.csv
```
--------------------------------
### Configure performance and processing
Source: https://context7.com/richardlehane/siegfried/llms.txt
Adjust parallel processing, IO throttling, and error handling for large scans.
```bash
# Scan up to 256 files in parallel
sf -multi 256 /path/to/documents
# Throttle scanning to reduce IO pressure (pause 50ms between files)
sf -throttle 50ms /path/to/documents
# Continue scanning despite file access errors
sf -coe /path/to/documents
# Follow symbolic links during scanning
sf -sym /path/to/documents
# Report file times in UTC instead of local timezone
sf -utc /path/to/documents
```
--------------------------------
### Build and Update Historical PRONOM Signature Files
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Commands to build an initial signature file and append historical PRONOM versions using the roy tool.
```bash
roy build -name v88 history.sig
```
```bash
roy add -droid DROID_SignatureFile_V81.xml -noreports -container container-signature-20150218.xml -name v81 history.sig
```
```bash
roy add -droid DROID_SignatureFile_V79.xml -noreports -container container-signature-20140923.xml -name v79 history.sig
```
```bash
roy add -droid DROID_SignatureFile_V78.xml -noreports -container container-signature-20140923.xml -name v78 history.sig
```
```bash
roy add -droid DROID_SignatureFile_V77.xml -noreports -container container-signature-20140717.xml -name v77 history.sig
```
--------------------------------
### Compare Results with Custom Join Options
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Specify how results files should be joined during comparison using the '-join' flag. Options range from joining on full path (default) to joining on hash only.
```bash
roy compare -join 0 myresults1.yaml myresults2.json // join on full path (default)
```
```bash
roy compare -join 1 myresults1.yaml myresults2.json // join on (local) filename only
```
```bash
roy compare -join 2 myresults1.yaml myresults2.json // join on filename and size
```
```bash
roy compare -join 3 myresults1.yaml myresults2.json // join on filename and modified
```
```bash
roy compare -join 4 myresults1.yaml myresults2.json // join on filename and hash
```
```bash
roy compare -join 5 myresults1.yaml myresults2.json // join on hash only
```
--------------------------------
### Inspect Priority Relationships with Graphviz
Source: https://context7.com/richardlehane/siegfried/llms.txt
Generates a Graphviz DOT file to visualize priority relationships. Pipe the output to the 'dot' command to create an image.
```bash
roy inspect priorities > priorities.dot
roy inspect p | dot -Tpng -o priorities.png
```
--------------------------------
### Regenerate Static Assets
Source: https://context7.com/richardlehane/siegfried/llms.txt
Run this command in the specified directory to regenerate static assets. Ensure you are in the correct project context.
```bash
cd pkg/static && go generate
```
--------------------------------
### List GPG keys including unusable subkeys
Source: https://github.com/richardlehane/siegfried/wiki/Release-process
Use this command to identify keys that have expired or are otherwise unusable.
```bash
gpg --list-options show-unusable-subkeys --list-keys
```
--------------------------------
### Scan file lists
Source: https://github.com/richardlehane/siegfried/blob/main/CHANGELOG.md
Use the -f flag to provide a file containing a list of paths to scan.
```bash
sf -f myfiles.txt
```
```bash
cat myfiles.txt | sf -f -
```
--------------------------------
### Build incremental signature file
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Creates a signature file containing only changes between specific PRONOM versions.
```bash
roy build -limit @78,@79,@81,@82 -name changes changes.sig
```
--------------------------------
### Save Named Configuration for Server Mode
Source: https://context7.com/richardlehane/siegfried/llms.txt
Saves a named configuration for server mode, specifying the port, enabling zip support, hash algorithm, and output file.
```bash
sf -setconf -serve :5138 -z -hash md5 -conf server.conf
```
--------------------------------
### Copy WASM Support File
Source: https://context7.com/richardlehane/siegfried/llms.txt
Copies the necessary 'wasm_exec.js' file from the Go SDK to the current directory. This file is required for the WASM binary to function in the browser.
```bash
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .
```
--------------------------------
### Configure Custom WikiBase Endpoint
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
Command to specify a custom WikiBase endpoint for harvesting file format information.
```bash
roy harvest -wikidataendpoint http://sparql.example.com
```
--------------------------------
### Inspect signature file metadata
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Displays details about the generated signature file, including inferred byte limits.
```bash
roy inspect tiff.sig
```
--------------------------------
### Expand Multiple Format Sets
Source: https://context7.com/richardlehane/siegfried/llms.txt
Expands multiple format sets (e.g., '@pdf', '@office', '@image') to list all contained formats within each set.
```bash
roy sets -list @pdf,@office,@image
```
--------------------------------
### Build a limited signature file
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Creates a signature file restricted to specific formats to improve scan performance.
```bash
roy build -limit @tiff -name tiff tiff.sig
```
--------------------------------
### Initialize Siegfried WASM
Source: https://github.com/richardlehane/siegfried/blob/main/wasm/example/index.html
Instantiate the WebAssembly module and attach the identify function to the environment.
```javascript
const go = new window.Go(); WebAssembly.instantiateStreaming( fetch("sf.wasm"), go.importObject ).then( (obj) => { go.run(obj.instance); } );
```
--------------------------------
### Execute File Identification
Source: https://github.com/richardlehane/siegfried/blob/main/wasm/example/index.html
Call the identify function with a FileSystemHandle and optional configuration arguments.
```javascript
identify(FSH, "z", "yaml", "sha1")
```
--------------------------------
### Server and Throttling Options
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Run Siegfried in server mode or control the rate of file scans.
```bash
sf -serve hostname:port
sf -throttle 10ms DIR
```
--------------------------------
### Perform initial scan with CSV output
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Runs a Siegfried scan and outputs results in CSV format for further processing.
```bash
sf -csv -sig tiff.sig DIR > 1pass.csv
```
--------------------------------
### Build a text-only signature file
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Create a signature file that only includes text identification rules. This is useful for using Siegfried as a standalone tool for identifying text encodings.
```bash
roy build -limit x-fmt/111 -name "text only" text.sig
```
--------------------------------
### Inspect signature configuration
Source: https://github.com/richardlehane/siegfried/wiki/Building-a-signature-file-with-ROY
Displays the current signature counts and details available to Siegfried.
```text
roy inspect
```
```text
Identifiers
Name: pronom
Details: ✨ signature development demo ✨
Number of filename signatures: 1
Number of MIME signatures: 1
Number of container signatures: 0
Number of XML signatures: 0
Number of byte signatures: 1
Number of RIFF signatures: 0
Number of text signatures: 1
```
--------------------------------
### Generate Change-Based Format Sets
Source: https://context7.com/richardlehane/siegfried/llms.txt
Generates format sets based on changes found in PRONOM release notes. Useful for updating sets incrementally.
```bash
roy sets -changes
```
--------------------------------
### Identify Uploaded File with Default Settings via POST
Source: https://context7.com/richardlehane/siegfried/llms.txt
Identifies an uploaded file using an HTTP POST request. Default output is YAML.
```bash
curl -F "file=@document.pdf" "http://localhost:5138/identify"
```
--------------------------------
### Inspect formats with Roy
Source: https://github.com/richardlehane/siegfried/blob/main/CHANGELOG.md
Use the roy inspect command to view details about specific formats.
```bash
roy inspect fmt/1 fmt/2
```
```bash
roy inspect @pdfa
```
--------------------------------
### Log unknown files during scan
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Alternative method to capture unknown files directly during the initial scan process.
```bash
sf -csv -sig tiff.sig -log unknown DIR > 1pass.csv 2> unknowns.txt
```
--------------------------------
### identify(FileSystemHandle, ...options)
Source: https://github.com/richardlehane/siegfried/blob/main/wasm/example/index.html
The identify function processes a FileSystemHandle to identify files, supporting various output formats, checksum algorithms, and archive decompression.
```APIDOC
## identify(FileSystemHandle, ...options)
### Description
Identifies files or directories provided via a FileSystemHandle. If a directory is provided, it recursively identifies all files within it.
### Parameters
#### Arguments
- **FileSystemHandle** (Object) - Required - A FileSystemHandle (file or directory) to be identified.
- **format** (String) - Optional - Output format: "json" (default), "yaml", "csv", or "droid".
- **checksum** (String) - Optional - Checksum algorithm: "md5", "sha1", "sha256", "sha512", or "crc".
- **z** (String) - Optional - Flag to enable decompression of archive formats (zip, tar.gz, WARC, ARC).
### Request Example
identify(FSH, "z", "yaml", "sha1")
### Response
#### Success Response (Promise)
- **result** (String) - A string representation of the identification results in the requested format.
```
--------------------------------
### Harvest Wikidata with Language Specification
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
Commands to specify the language for Wikidata results during harvest.
```bash
/roy harvest -wikidata -lang
```
```bash
/roy harvest -wikidata -lang de
```
--------------------------------
### Inspect priorities
Source: https://github.com/richardlehane/siegfried/blob/main/CHANGELOG.md
Generate graphs of priority relations or list missing/implicit priorities.
```bash
roy inspect implicit-priorities
```
```bash
roy inspect missing-priorities
```
```bash
roy inspect priorities
```
--------------------------------
### Build with Debug Linting
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
Command to build the identifier with additional linting information enabled.
```bash
roy build -wikidatadebug
```
--------------------------------
### Calculate checksums with sf
Source: https://context7.com/richardlehane/siegfried/llms.txt
Generate file checksums during the identification process.
```bash
# Calculate MD5 checksum
sf -hash md5 document.pdf
# Calculate SHA256 checksum with JSON output
sf -json -hash sha256 /path/to/documents > results.json
# Calculate SHA1 checksums for files in a directory
sf -hash sha1 -csv /path/to/documents > results_with_hash.csv
```
--------------------------------
### Expand Single Format Set
Source: https://context7.com/richardlehane/siegfried/llms.txt
Expands a single format set (e.g., '@pdf') to list all contained formats. Use the '@' prefix to denote a format set.
```bash
roy sets -list @pdf
```
--------------------------------
### Inspect Missing Priority Relationships
Source: https://context7.com/richardlehane/siegfried/llms.txt
Generates a Graphviz DOT file to visualize missing priority relationships. Pipe the output to the 'dot' command to create an image.
```bash
roy inspect missing-priorities > missing.dot
roy inspect mp | dot -Tpng -o missing.png
```
--------------------------------
### Compare Multiple Identification Tools
Source: https://context7.com/richardlehane/siegfried/llms.txt
Compares identification results from different tools (siegfried, DROID, FIDO) and outputs the comparison to a CSV file.
```bash
roy compare sf-results.yaml droid-results.csv fido-results.csv > comparison.csv
```
--------------------------------
### Replay Scan from YAML Results
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Simulate a scan using a YAML results file. This is useful for re-processing or converting results.
```bash
sf -replay myresults.yaml
```
--------------------------------
### Create and Use Empty Identifiers
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Methods to create a signature file that skips identification to perform only ancillary tasks like hashing or listing.
```bash
roy build -limit null -name empty empty.sig
```
```bash
roy build -exclude @all -name empty empty.sig
```
```bash
sf -sig empty.sig -z -csv -hash crc DIR
```
--------------------------------
### Scan files from a specified list file
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Use the -f flag followed by a filename to scan each file and directory listed within that file.
```bash
sf -f myfiles.txt
```
--------------------------------
### Identify files with sf
Source: https://context7.com/richardlehane/siegfried/llms.txt
Basic usage for identifying file formats using various output formats and input sources.
```bash
# Basic file identification (YAML output by default)
sf document.pdf
# Scan a directory recursively
sf /path/to/documents
# Scan multiple files and directories
sf file1.doc file2.xlsx /path/to/folder
# Output in JSON format
sf -json document.pdf
# Output in CSV format
sf -csv /path/to/documents > results.csv
# Output in DROID CSV format (compatible with TNA's DROID tool)
sf -droid /path/to/documents > droid_results.csv
# Scan without recursing into subdirectories
sf -nr /path/to/documents
# Scan from stdin with optional filename hint
cat unknown_file | sf -name unknown_file.bin -
# Scan files from a list
sf -f file_list.txt
```
--------------------------------
### Inspect Wikidata Signature with Roy
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
Use the 'roy inspect' command followed by '-wikidata' and a Wikidata QID to view the compiled signature information for a given identifier. This is useful for debugging and understanding how a signature is represented.
```bash
roy inspect -wikidata
```
```bash
roy inspect -wikidata Q27881556
```
--------------------------------
### Build Wikidata Identifiers
Source: https://github.com/richardlehane/siegfried/wiki/Wikidata-identifier
Commands to compile the identifier with or without PRONOM integration.
```bash
roy build -wikidata
```
```bash
roy build -wikidata -nopronom
```
--------------------------------
### Load Siegfried WASM in a Web Page
Source: https://github.com/richardlehane/siegfried/blob/main/wasm/README.md
Include the necessary JavaScript and WASM files to initialize the Siegfried module in a browser environment.
```html
```
--------------------------------
### Harvest PRONOM Release Notes
Source: https://context7.com/richardlehane/siegfried/llms.txt
Harvests PRONOM release notes to obtain changelog information.
```bash
roy harvest -changes
```
--------------------------------
### Compare Results Joining on Filename and Hash
Source: https://context7.com/richardlehane/siegfried/llms.txt
Compares two results files, joining records based on filename and file hash (e.g., MD5, SHA1). This is a strong indicator of identical files.
```bash
roy compare -join 4 results1.yaml results2.yaml > comparison.csv
```
--------------------------------
### Directory Scanning Options
Source: https://github.com/richardlehane/siegfried/blob/main/README.md
Control subdirectory scanning and decompression behavior.
```bash
sf -nr DIR
sf -z file.zip | *.ext | DIR
sf -zs gzip,tar file.tar.gz | *.ext | DIR
```
--------------------------------
### Concatenate Results Files using Replay
Source: https://github.com/richardlehane/siegfried/wiki/Identifying-file-formats
Combine multiple results files into a single output file using the replay command. The output format is determined by the last file's extension or specified flags.
```bash
sf -replay myresults.yaml moreresults.csv > allresults.yaml
```
--------------------------------
### Apply Historical Signature Files
Source: https://github.com/richardlehane/siegfried/wiki/Tips-and-Tricks
Pipes a filtered list of files into a secondary identification process using a multi-identifier signature file.
```bash
sf -sig changes.sig -log known,stdout DIR | sf -sig history.sig -f -
```