1.8 SilkFile Object

An SilkFile object represents a channel for writing to or reading from SiLK flow files. A SiLK file open for reading can be iterated over using for rec in file.

class SilkFile( filename, mode, compression=DEFAULT, notes=[], invocations=[] )
The constructor takes a filename, a mode, and a set of optional keyword parameters. The filename should be the path to the file to open. The mode should be one of the following constant values:
Mode Meaning
READ Open file for reading
WRITE Open file for writing
APPEND Open file for appending


The compression parameter can be one of the following constants:

Constant Meaning
DEFAULT Default compression scheme compiled into SiLK
NO_COMPRESSION No compression
ZLIB Use zlib block compression
LZO1X Use lzo1x block compression

If notes or invocations are set, they should be list of strings. These add annotation and invocation headers to the file.

Examples:

>>> myinputfile = SilkFile('/path/to/file', READ)
>>> myoutputfile = SilkFile('/path/to/file', WRITE, compression=LZO1X,
                            notes=['My output file',
                                   'another annotation'])

Instance methods:

read( )
Returns an RWRec representing the next record in the SilkFile. If there are no records left in the file, returns None.

write( rec)
Writes the RWRec rec to the file. Returns None.

next( )
A SilkFile object is its own iterator, for example iter(f) returns f. When the SilkFile is used as an iterator, the next() method is called repeatedly. This method returns the next record, or raises StopIteration when EOF is hit.

notes( )
Returns the list of annotation headers for the file as a list of strings.

invocations( )
Returns the list of invocation headers for the file as a list of strings.

close( )
Closes the file. Returns None.