scistag.filestag.file_stag.FileStag¶
- class FileStag[source]¶
Bases:
objectHelper class to load data from a variety of sources such as local files, registered archives of the web
Methods
Copies a file from given source to given target location
Deletes a file
Verifies if a file exists
Returns if the file path points to a simple file on disk which does not require loading it to memory
Loads a file by filename from a local file, a registered web archive or the web
Loads a json dictionary from a given file source
Loads a text file from a given file source
Saves data to a file
Saves json data to a file target
Saves text data to a file
Attributes
__dict____doc____module____weakref__list of weak references to the object (if defined)
- classmethod copy(source, target, create_dir=False, **params)[source]¶
Copies a file from given source to given target location
- classmethod is_simple(filename)[source]¶
Returns if the file path points to a simple file on disk which does not require loading it to memory
- Parameters
filename (FileSourceTypes | FileTargetTypes) – The file’s source such as a local filename or URL. See
FileNameType- Return type
- Returns
True if it is a normal, local file
- classmethod load(source, **params)[source]¶
Loads a file by filename from a local file, a registered web archive or the web
- Parameters
source (FileSourceTypes) – The file’s source such as a local filename or URL. See
FileNameTypeparams – Advanced loading params passed to the file loader such as
timeout_sormax_cache_agefor files from the web.
- Return type
bytes | None
- Returns
The data if the file could be found
- classmethod load_json(source, encoding='utf-8', **params)[source]¶
Loads a json dictionary from a given file source
- classmethod load_text(source, encoding='utf-8', **params)[source]¶
Loads a text file from a given file source
- classmethod save_json(target, data, indent=None, encoding='utf-8', **params)[source]¶
Saves json data to a file target
- Parameters
target (FileTargetTypes) – The file’s target. See
FileNameTypedata (dict) – The dictionary to be stored
indent (int | None) – The json indenting. None by default
encoding (str) – The encoding to use. utf-8 by default.
params – The advanced storage parameters, depending on the type of storage, such as timeout_s for file’s stored via network.
- Return type
- Returns
True on success