-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
88 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ A full Release object has the following properties attached on it, all of which | |
For more information on the Debian Repository Format, see https://wiki.debian.org/DebianRepository/Format.<br> | ||
|
||
```ts | ||
interface Release { | ||
interface IRelease { | ||
architectures: string[] // => Architectures | ||
noSupportForArchitectureAll?: boolean // => No-Support-For-Architecture-All | ||
description?: string // => Description | ||
|
@@ -57,18 +57,99 @@ type ReleaseHash = { | |
} | ||
``` | ||
### Binary Control Parsing | ||
Here's an example for getting the information out of a binary control file:<br> | ||
```ts | ||
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 <[email protected]> | ||
Section: Applications | ||
Version: 2.2.1-2 | ||
Installed-Size: 1536 | ||
Custom-Key: cool-value | ||
`; | ||
|
||
const control = new BinaryControl(data); | ||
|
||
console.log(control.version); // => 2.2.1-2 | ||
console.log(control.package); // => com.amywhile.signalreborn | ||
console.log(control.get('Custom-Key')); // => cool-value | ||
console.log(control.get('Invalid-Key')); // => null | ||
``` | ||
|
||
A full BinaryControl object has the following properties attached on it, all of which map to documented APT fields.<br> | ||
For more information on the Debian Control Format, see https://www.debian.org/doc/debian-policy/ch-controlfields.html.<br> | ||
|
||
```ts | ||
interface IBinaryControl { | ||
package: string // => Package | ||
source?: string // => Source | ||
version: string // => Version | ||
section?: string // => Section | ||
priority?: PriorityLevel // => Priority | ||
architecture: string // => Architecture | ||
essential?: boolean // => Essential | ||
|
||
depends?: string[] // => Depends | ||
preDepends?: string[] // => Pre-Depends | ||
recommends?: string[] // => Recommends | ||
suggests?: string[] // => Suggests | ||
replaces?: string[] // => Replaces | ||
enhances?: string[] // => Enhances | ||
breaks?: string[] // => Breaks | ||
conflicts?: string[] // => Conflicts | ||
|
||
installedSize?: number // => Installed-Size | ||
maintainer: string // => Maintainer | ||
description: string // => Description | ||
homepage?: string // => Homepage | ||
builtUsing?: string // => Built-Using | ||
packageType?: PackageType // => Package-Type | ||
|
||
get(key: string): string | undefined // => Retrieve a raw field value not assigned a strict type | ||
get fieldCount(): number // => Get total number of fields in the Release contents | ||
} | ||
``` | ||
|
||
### Packages Parsing | ||
*Package parsing will have strictly defined types soon*<br> | ||
Here's an example for getting the information out of a Packages file:<br> | ||
```ts | ||
import axios from 'axios'; | ||
import { parsePackages } from 'apt-parser'; | ||
import { Packages } from 'apt-parser'; | ||
|
||
const { data } = await axios.get('https://repo.chariz.com/Packages'); | ||
const packages = parsePackages(data); | ||
const packages = new Packages(data); | ||
|
||
for (const pkg of packages) { | ||
console.log(pkg.package); // Package Identifier | ||
console.log(pkg.get('InvalidKey')); // => null | ||
} | ||
``` | ||
|
||
A full Packages object has the following properties attached on it, all of which map to documented APT fields.<br> | ||
For more information on the Debian Repository Format, see https://wiki.debian.org/DebianRepository/Format.<br> | ||
|
||
```ts | ||
interface IPackage extends IBinaryControl { | ||
filename: string // => Filename | ||
size: number // => Size | ||
md5?: string // => MD5sum | ||
sha1?: string // => SHA1 | ||
sha256?: string // => SHA256 | ||
sha512?: string // => SHA512 | ||
descriptionMd5?: string // => Description-md5 | ||
|
||
get(key: string): string | undefined // => Retrieve a raw field value not assigned a strict type | ||
get fieldCount(): number // => Get total number of fields in the Release contents | ||
} | ||
|
||
for (const packageMap of packages) { | ||
console.log(packageMap.get('Package')); // Package Identifier | ||
console.log(packageMap.get('InvalidKey')); // => null | ||
interface IPackages extends Array<IPackage> { | ||
constructor(rawData: string) // Pass in the raw contents of the file | ||
} | ||
``` |