APT Parser
This library is capable of parsing files used within the APT Package Manager.
A typical APT repository advertises a release file and packages file, utilizing a key-value organization system.
This library is able to parse the data and return it as type-safe objects for usage in JavaScript and TypeScript projects.
Installation
npm install --save apt-parser
Release Parsing
Here's an example for getting the information out of a Release file:
import axios from 'axios';
import { Release } from 'apt-parser';
const { data } = await axios.get('http://archive.ubuntu.com/ubuntu/dists/jammy/Release');
const release = new Release(data);
console.log(release.origin);
console.log(release.version);
console.log(release.get('InvalidKey'));
A full Release object has the following properties attached on it, all of which map to documented APT fields.
For more information on the Debian Repository Format, see <https://wiki.debian.org/DebianRepository/Format.
>
interface IRelease {
architectures: string[]
noSupportForArchitectureAll?: boolean
description?: string
origin?: string
label?: string
suite: string
codename: string
version?: string
date?: Date
validUntil?: Date
components: string[]
md5?: ReleaseHash[]
sha1?: ReleaseHash[]
sha256?: ReleaseHash[]
sha512?: ReleaseHash[]
notAutomatic?: boolean
butAutomaticUpgrades?: boolean
acquireByHash?: boolean
signedBy?: string[]
packagesRequireAuthorization: boolean
get(key: string): string | undefined
get fieldCount(): number
}
type ReleaseHash = {
filename: string
hash: string
size: number
}
Binary Control Parsing
Here's an example for getting the information out of a binary control file:
import { Release } from 'apt-parser';
const data =
`
Package: com.amywhile.signalreborn
Architecture: iphoneos-arm
Description: Visualise your nearby cell towers
Depends: firmware (>= 12.2) | org.swift.libswift
Maintainer: Amy While <support@anamy.gay>
Section: Applications
Version: 2.2.1-2
Installed-Size: 1536
Custom-Key: cool-value
`;
const control = new BinaryControl(data);
console.log(control.version);
console.log(control.package);
console.log(control.get('Custom-Key'));
console.log(control.get('Invalid-Key'));
A full BinaryControl object has the following properties attached on it, all of which map to documented APT fields.
For more information on the Debian Control Format, see <https://www.debian.org/doc/debian-policy/ch-controlfields.html.
>
interface IBinaryControl {
package: string
source?: string
version: string
section?: string
priority?: PriorityLevel
architecture: string
essential?: boolean
depends?: string[]
preDepends?: string[]
recommends?: string[]
suggests?: string[]
replaces?: string[]
enhances?: string[]
breaks?: string[]
conflicts?: string[]
installedSize?: number
maintainer: string
description: string
homepage?: string
builtUsing?: string
packageType?: PackageType
get(key: string): string | undefined
get fieldCount(): number
}
Packages Parsing
Here's an example for getting the information out of a Packages file:
import axios from 'axios';
import { Packages } from 'apt-parser';
const { data } = await axios.get('https://repo.chariz.com/Packages');
const packages = new Packages(data);
for (const pkg of packages) {
console.log(pkg.package);
console.log(pkg.get('InvalidKey'));
}
A full Packages object has the following properties attached on it, all of which map to documented APT fields.
For more information on the Debian Repository Format, see <https://wiki.debian.org/DebianRepository/Format.
>
interface IPackage extends IBinaryControl {
filename: string
size: number
md5?: string
sha1?: string
sha256?: string
sha512?: string
descriptionMd5?: string
get(key: string): string | undefined
get fieldCount(): number
}
interface IPackages extends Array<IPackage> {
constructor(rawData: string)
}
Skipping Validation
The parser validates required fields based on the parameters defined by the Debian Team on their documentation pages.
Disabling this validation is possible, but it is not recommended if you are parsing valid repositories.
Disabling this validation will stop the APT parser from throwing any MissingRequiredKeyError
s.
It is disabled through an option when constructing your parser.
import axios from 'axios';
import { Packages } from 'apt-parser';
const { data } = await axios.get('https://repo.chariz.com/Packages');
const packages = new Packages(data, {
skipValidation: true
});