Skip to content

Latest commit

 

History

History
55 lines (33 loc) · 1.42 KB

api.rst

File metadata and controls

55 lines (33 loc) · 1.42 KB

API

The primary sphobjinv API consists of two pairs of functions:

  • ~sphobjinv.sphobjinv.readfile / ~sphobjinv.sphobjinv.writefile -- Read/write files from/to disk as , for proper behavior of zlib (de)compression.
  • ~sphobjinv.sphobjinv.encode / ~sphobjinv.sphobjinv.decode -- Encode/decode the object data read from disk.

Also exposed are two patterns, potentially useful in parsing decoded data only:

  • ~sphobjinv.sphobjinv.p_comments -- Retrieves the #-prefixed comment lines
  • ~sphobjinv.sphobjinv.p_data -- Retrieves all lines not prefixed by #

The normal workflow would be:

  1. Import the module; e.g.:

    >>> import sphobjinv as soi
  2. Read the desired file data (compressed or uncompressed) with ~sphobjinv.sphobjinv.readfile:

    >>> fd = soi.readfile('/path/to/file')
  3. Decode [or encode] the file data with ~sphobjinv.sphobjinv.decode [or ~sphobjinv.sphobjinv.encode]:

    >>> data = soi.decode(fd)
  4. Write the desired file with ~sphobjinv.sphobjinv.writefile, or otherwise use the resulting data:

    >>> len(soi.p_data.findall(data))   # e.g., retrieve the number of object entries
    6319
    
    >>> soi.writefile('/path/to/new/file', data)

Members

sphobjinv.sphobjinv