mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
internal/archive reads ZIP, ARC (stored, packed, squeezed, crunched, squashed), ARJ (methods 0 to 4) and LHA (-lh0-, -lh4- to -lh7-, header levels 0 to 2) in Go, with no other programs, and writes ARC, ARJ and LHA stored. Sizes are checked before memory is given to them and every entry against its CRC; it was fuzzed, and stressed with 350,000 damaged archives (none slower than 30 ms). The test archives were made by the real programs (arc 5.21q, ARJ32 3.10, jlha), and what is written here passes their own tests. Bundles from links are tossed whatever their format (known by their first bytes, not their names); packer = arc, arj or lha bundles in those (stored). A test packs packets with the real programs, compressing, where they are installed. The file base lists and takes FILE_ID.DIZ from ARC, ARJ and LHA archives too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
47 lines
929 B
Go
47 lines
929 B
Go
package archive
|
|
|
|
import (
|
|
"archive/zip"
|
|
"bytes"
|
|
"io"
|
|
"time"
|
|
)
|
|
|
|
// File is a file to put in an archive.
|
|
type File struct {
|
|
Name string
|
|
Data []byte
|
|
Modified time.Time
|
|
}
|
|
|
|
// Write writes files as an archive of the kind (called name, which ARJ
|
|
// keeps): ZIP deflated, the others stored.
|
|
func Write(w io.Writer, kind Kind, name string, files []File) error {
|
|
switch kind {
|
|
case ZIP:
|
|
var b bytes.Buffer
|
|
zw := zip.NewWriter(&b)
|
|
for _, f := range files {
|
|
fw, err := zw.CreateHeader(&zip.FileHeader{Name: f.Name, Method: zip.Deflate, Modified: f.Modified})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, err := fw.Write(f.Data); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if err := zw.Close(); err != nil {
|
|
return err
|
|
}
|
|
_, err := w.Write(b.Bytes())
|
|
return err
|
|
case ARC:
|
|
return writeARC(w, files)
|
|
case ARJ:
|
|
return writeARJ(w, name, files)
|
|
case LHA:
|
|
return writeLHA(w, files)
|
|
}
|
|
return ErrFormat
|
|
}
|