GithubHelp home page GithubHelp logo

apt-client's Introduction

Apt-Client

A basic Apt client for node and the browser, so you can get information about debian packages.

  • new AptClient(sources?: string[], arch?: string, cachetime? number) Constructs a new client for a possibly-empty list of source and optionally-specified architecture (defaults to 'all'). The sources should be strings just like you would see in a sources.list file, one per line, or URLs directly to a Sources(.gz) or Packages(.gz) file. If cachetime is specified, client.update will avoid re-requesting data for particular sources if they have already been requested within the last cachetime milliseconds.

  • client.update(sources?: string[], arch?: string, cachetime? number, clear?: boolean): Promise<[string, string][]> Rewrites the local cache with data fetched from the specified sources. The first three arguments default to the values provided to the constructor. This allows you the flexibility to specify a source list, target architecture, or cache timeout at client-creation time, or at update time. The clear parameter specifies whether the cached package data should be totally replaced, or only updated--the latter is useful if you wish to re-request a specific source without wiping out cached data previously requested from other sources. This defaults to true. The return value is a list of error pairs, with the first element of each pair being a description of the error, and the second being the repo spec or URL on which the error occurred.

  • client.getPackages(): { bin: string[], src: string[] } Returns lists of the names of all packages available as binaries or source.

  • client.listVersions(pkgName: string): { bin: string[], src: string[] } For a given package name, returns all of the versions available in binary or source formats.

  • client.getPkgInfo(pkgNames: Iterable<string>): Promise<{ bin: Map<string, PkgInfo<BinPkgInfo>>, src: Map<string, PkgInfo<SrcPkgInfo>> }> Gets detailed information about the named packages.

  • client.getBinFiles(pkgNames: Iterable<string>, checkHash=true): Promise<Map<string, ArrayBuffer | null>> Gets the binary .deb files for a list of packages as ArrayBuffers. If checkHash is not false, and an MD5, SHA1, or SHA256 hash was specified for a given package, the downloaded file data will be discarded and the package's entry in the returned map set to null unless the hash verification passes.

  • client.getSrcFiles(pkgNames: Iterable<string>, checkHash=true): Promise<Map<string, { [key: string]: ArrayBuffer | null}>> Gets the source files for a list of packages, with the sources of each package provided as an object mapping from source file name to ArrayBuffer. If checkHash is not false, files listed in the package Files must match their specified size, and files listed in the ChecksumsSha1 or ChecksumsSha256 sections must match the provided hash, or their data will be discarded and the file's entry in the returned map will be set to null.

  • client.isLatest(pkgName: string, version: string): boolean Checks if a given package version is the latest. Defaults to true if the package is not found in the cached sources. Checks against binary packages first, and source versions if the binary does not exist.

  • client.areLatest(packages: Iterable<[pkgName: string, version: string]>): Generator<[string, boolean]> Checks if each package is at the latest version, with the same algorithm as client.isLatest.

  • client.getLatest(packages: Iterable<string>): Generator<[pkgName: string, version: string]> Gets the latest version of each package available as a binary, or as a source if no binaries are available.

  • client.areAllLatest(packages: Iterable<[pkgName: string, version: string]>): boolean Checks if all the requested packages are up to date; this is more efficient than client.areLatest due to short-circuiting on the first non-up-to-date package.

  • AptClient.cmpVersions(a: string, b: string): number Compares two Debian package version strings and returns < 0 if a is less than b, > 0 if a is greater than b, and 0 if a equals b.

  • type PkgInfo<T> { latest: string, versions: Map<string, T> } For a given package, caches the latest version available and provides a map from version numbers to more detailed information about that package version.

Data guaranteed to be available on all package version info objects includes:

  • Package: string The package name
  • RepoBase: string The URL to the repository from which this information was obtained.
  • Version: string The version of the package being described.
  • Maintainer: { name: string, email: string } Contact information for the package maintainer. (Note that while the object is guaranteed to be present, the name, email, or both may be empty strings.)

Additional data guaranteed to be available on all version objects for binary packages includes:

  • Architecture: string[] A list of architectures for which binaries are available.
  • InstalledSize: number
  • Description: string
  • Filename: string A relative URL specifying where the binary file is stored in the repository.
  • Size: number

Additional data guaranteed to be available on all version objects for source packages includes:

  • Directory: string A relative URL specifying the directory in which source files are stored in the repository.
  • Files: { name: string, hash: string, size: number }[] A list of objects describing the individual source files.

Numerous other optional fields may or may not be present depending on their presence in the specific repository being queried.

apt-client's People

Contributors

dependabot[bot] avatar gliese1337 avatar idolize avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

apt-client's Issues

aptreader throws an exception if a package's Maintainer field is empty

Hey. Thanks for putting this package out!

I'm trying to parse the default APT lists of a Raspberry Pi Zero W, but noticed that there's a package in there which causes aptreader to throw an exception.

The source list is

deb http://archive.raspberrypi.org/debian/ buster main

which the library resolves to the following URL (not sure if the // is intended behavior?):

http://archive.raspberrypi.org/debian//dists/buster/main/binary-armhf/Packages

and the package definition (or rather, one of the few) which causes the parser to fail is:

Package: kodi
Architecture: all
Breaks: xbmc (<< 2:14.0~git20141019), xbmc-data, xbmc-standalone
Depends: kodi-bin (>= 2:18.7-1~buster), kodi-bin (<< 2:18.7-1~buster.1~), curl, libcurl4 | libcurl3, mesa-utils, x11-utils, fonts-liberation | ttf-liberation, fonts-dejavu-core | ttf-dejavu-core, python-bluez | python-lightblue, python-imaging | python-pil, python-simplejson, libass9 | libass5 | libass4, libgif5 | libgif7, libnfs12 | libnfs8 | libnfs4 | libnfs1, libbluray1 | libbluray2, libshairplay0, libvorbisfile3, libaacs0, libcec4, libgnutls30 | libgnutls-deb0-28 | libgnutls28 | libgnutls26, libxslt1.1, libegl1, libgles2, policykit-1
Priority: optional
Section: video
Filename: pool/main/k/kodi/kodi_18.7-1~buster_all.deb
Size: 22932518
SHA256: d6f32afbf32540a76ea72b50d90a5f32175b04e88cc0282e78c40c213beee3ac
SHA1: 15682fae6cedfc74bd82c32f2437572f4fdcfb1a
MD5sum: d91d467be1973f66916de39af2b9a6cc
Description: Kodi Media Center (arch-independent data package)
 Kodi, formerly known as XBMC Media Center, is an award winning free and open
 source software media-player and entertainment hub for all your digital media.
 Kodi is available for Linux, Mac OS X (Leopard, Tiger and Apple TV) and
 Microsoft Windows, as well as the original Xbox game console. Created in 2003
 by a group of like minded programmers, Kodi is a non-profit project run and
 developed by volunteers located around the world. More than 50 software
 developers have contributed to Kodi, and 100-plus translators have worked to
 expand its reach, making it available in more than 30 languages.
 .
 While Kodi functions very well as a standard media player application for your
 computer, it has been designed to be the perfect companion for your HTPC.
 Supporting an almost endless range of remote controls, and combined with its
 beautiful interface and powerful skinning engine, Kodi feels very natural to
 use from the couch and is the ideal solution for your home theater. Once
 installed, your computer will become a fully functional multimedia jukebox.
 .
 This package contains Kodi's architecture independent data.
Homepage: http://kodi.tv
Maintainer:  <>
Provides: kodi-data, kodi-skin-estuary, kodi-standalone, xbmc, xbmc-data, xbmc-standalone
Recommends: libvdpau1, libva-intel-vaapi-driver, libva1
Replaces: xbmc (<< 2:14.0~git20141019), xbmc-data, xbmc-standalone
Source: kodi
Suggests: kodi-pvr-mythtv, kodi-pvr-vuplus, kodi-pvr-vdr-vnsi, kodi-pvr-njoy, kodi-pvr-nextpvr, kodi-pvr-mediaportal-tvserver, kodi-pvr-tvheadend-hts, kodi-pvr-dvbviewer, kodi-pvr-argustv, kodi-pvr-iptvsimple, kodi-audioencoder-vorbis, kodi-audioencoder-flac, kodi-audioencoder-lame
Version: 2:18.7-1~buster
Installed-Size: 38801

As you can see, the Maintainer field is empy, which causes the following error to be thrown:

Exception has occurred: TypeError: Cannot read property 'replace' of undefined
  at toContactInfo (/home/user/Projects/apt-testing/node_modules/apt-client/dist/aptreader.js:55:12)
    at /home/user/Projects/apt-testing/node_modules/apt-client/dist/aptreader.js:248:32
    at Generator.next (<anonymous>)
    at fulfilled (/home/user/Projects/apt-testing/node_modules/apt-client/dist/aptreader.js:15:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

which resolves to the following line:

return { name: name.replace(/"|^\s+|\s+$/g, '') , email: email.trim() };

The toContactInfo function gets called with the s parameter being '<>', so the first regexes match, but after being destructured, the first capture group (name) is undefined, causing the error at hand.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.