scistag.filestag.archive_file_sink.ArchiveFileSinkProto

class ArchiveFileSinkProto(target, **params)[source]

Bases: FileSink

The archive file sink is an abstract base class for FileSinks which are able to summarize their content in a single byte stream and are thus for example capable of bundling data batch-wise e.g. to upload them to the cloud.

Do not use this class directly. if you want to collect files in a zip archive use FileSinkZip.

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

  • 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()

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