2
1
Fork
You've already forked cab4j
0
Microsoft Cabinet writing and reading library using pure Java NIO
  • Java 99.9%
  • C 0.1%
Moritz Hofmann 1aa903e919
Some checks failed
CI / build (push) Successful in 3m15s
Release / publish (push) Failing after 3m36s
ci: Fix release pipeline
2025年11月09日 15:23:44 +01:00
.forgejo/workflows ci: Fix release pipeline 2025年11月09日 15:23:44 +01:00
.idea feat: Improved Cab Extractor 2025年09月10日 12:09:39 +02:00
.mvn/wrapper chore: Add maven wrapper 2025年08月05日 16:06:40 +02:00
docu docs: Add MS Docs for LZX compression 2025年06月17日 14:16:11 +02:00
src test: Add more tests 2025年09月10日 14:25:08 +02:00
test fix: Add remaining structures 2024年04月25日 11:04:28 +02:00
.gitignore Initial commit 2024年04月24日 22:00:55 +02:00
jitpack.yml build: Change version to v0.1.0-beta2 2025年08月04日 22:50:19 +02:00
LICENSE docs: Add email to name 2025年08月04日 22:39:31 +02:00
mvnw chore: Add maven wrapper 2025年08月05日 16:06:40 +02:00
mvnw.cmd chore: Add maven wrapper 2025年08月05日 16:06:40 +02:00
pom.xml build: Increase version 2025年11月09日 14:55:09 +01:00
README.md docs: Update readme 2025年09月10日 14:26:18 +02:00

🗄️ cab4j - Cabinet Files in pure Java

A Java library for creating and reading cabinet files (*.cab) with Java using NIO ByteBuffer. It was created using the official Microsoft CAB Documentation and has almost no dependencies.

Features

  • Checksum supported
  • makes only use of Java NIO2 ByteBuffers
  • Uncompressed, MSZIP, Quantum/LZX compression support
  • Recursive directory packing with subfolder support
  • Splitting archives into multiple cabinets
  • Java 8+ compatible

📃 Testing and official docs

  • Test files are located in test/ (sample sources from the spec in docu/).
  • Build and run tests with JDK 11+: ./mvnw -B -ntp verify.

Extractor API

The extractor implementation lives under de.morihofi.cab4j.extract. Use the static methods on CabExtractor:

// In-memoryMap<String,ByteBuffer>files=CabExtractor.extract(cabBuffer);// With attributesMap<String,CabExtractor.FileData>meta=CabExtractor.extractWithAttributes(cabBuffer);// Streaming to a directoryCabExtractor.extractToDirectory(channel,outputDir);

Exceptions

Common runtime exceptions are under de.morihofi.cab4j.exceptions:

  • CabFormatException (invalid/unsupported format),
  • CabChecksumMismatchException (CFDATA checksum mismatch),
  • CabDecompressionException (codec errors),
  • CabDuplicateFileException, CabTooManyFilesOrFolderException, CabFileTooLargeException.

File attributes

CabArchive.addFile(Path) automatically records DOS file attributes like read-only or hidden when available. You can also specify attributes manually using

archive.addFile("name.txt",buffer,CfFile.ATTRIB_READONLY|CfFile.ATTRIB_HIDDEN);

Use CabExtractor.extractWithAttributes to retrieve these attributes or extractToDirectory to restore them on disk.

Directory packing

You can add entire directory trees using CabArchive.addDirectory(Path). Relative paths are preserved inside the cabinet. When building large archives you can split the output into multiple cabinets using CabGenerator:

CabArchivearchive=newCabArchive();archive.addDirectory(Paths.get("assets"));CabGeneratorgenerator=newCabGenerator(archive);List<ByteBuffer>cabs=generator.createCabinetSet(1_000_000);// split after 1 MB

File timestamps

CabArchive.addFile(Path) also preserves the last modified time of the source file. When extracting with extractWithAttributes the returned ExtractedFile contains this timestamp and extractToDirectory restores it on disk. The time format follows the same semantics as the Java ZIP API.