scistag.filestag.zip_file_sink.ZipFileSink

class ZipFileSink(target, compression=20, **params)[source]

Bases: ArchiveFileSinkProto

Defines an in-memory file sink which stores all files in a zip archive - by default an archive in the memory.

After all files have been added they can be received via get_data() as a single bytes string.

Parameters
  • target (str) – The sink’s storage target

  • compression – The compression level to be used from 0 (pure storage) to 100 (best compression)

  • params – Additional initializer parameters. See FileSink.

Methods

close

This function should be called when ever you finished adding all files to the file sink to finalize it (e.g.

get_data

Returns the archive's content as single bytes string.

store

Stores a single file in the file sink

with_target

Creates a file source with given target.

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

_store_int(filename, data, overwrite, options=None)[source]

The internal storage function to be implemented for the different kinds of target types.

Parameters
  • filename (str) – The name of the file to be stored

  • data (bytes) – The data to be stored

  • options (FileStorageOptions | None) – Advanced storage and file options

Return type

bool

Returns

True on success

close()[source]

This function should be called when ever you finished adding all files to the file sink to finalize it (e.g. a zip archive)

Alternatively you can create and fill the sink within a with block such as

get_data()[source]

Returns the archive’s content as single bytes string.

Return type

bytes

Returns

The sink’s data, e.g. the byte stream of a zip archive.

store(filename, data, overwrite=True, options=None)

Stores a single file in the file sink

Parameters
  • filename (str) – The file’s name

  • data (bytes) – The data to be stored

  • overwrite (bool) – Defines if the file may be overwritten if it does already exist.

  • options (FileStorageOptions | None) – Advanced storage and file options

Return type

bool

Returns

True on success

static with_target(target, **params)

Creates a file source with given target.

Parameters
  • target (str) –

    The target cloud storage or zip archive at which the data shall be stored.

    Supported types (as of now) are: - “azure://DefaultEndpoints…” to store data in a

    FileSinkAzureStorage

    • ”zip://” w/o a filename to create a memory zip

  • params – Further parameters to be passed on

Returns

The FileSink instance

_closed

Defines if the file sink was finalized (e.g. a zip archive closed)

_target

The sink’s storage target