Anklang 0.3.0-460-gc4ef46ba
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
storage.hh
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#ifndef __ASE_STORAGE_HH__
3#define __ASE_STORAGE_HH__
4
5#include <ase/defs.hh>
6
7namespace Ase {
8
9class Storage {
10protected:
11 virtual ~Storage () = 0;
12public:
13 enum StorageFlags {
14 NONE = 0,
15 AUTO_ZSTD = 1,
16 };
17};
18
19class StorageWriter : public Storage {
20 class Impl;
22public:
23 explicit StorageWriter (StorageFlags = StorageFlags::NONE);
24 virtual ~StorageWriter ();
25 // Writer API
26 Error open_for_writing (const String &filename);
27 Error open_with_mimetype (const String &filename, const String &mimetype);
28 Error store_file_data (const String &filename, const String &buffer, bool alwayscompress = false);
29 Error store_file (const String &filename, const String &ondiskpath, bool maycompress = true);
30 Error close ();
31 Error remove_opened ();
32};
33
34class StorageReader : public Storage {
35 class Impl;
37public:
38 explicit StorageReader (StorageFlags = StorageFlags::NONE);
39 virtual ~StorageReader ();
40 // Reader API
41 Error open_for_reading (const String &filename);
42 void search_dir (const String &dirname);
43 bool has_file (const String &filename);
44 StringS list_files ();
45 String stringread (const String &filename, ssize_t maxlength = -1);
46 Error close ();
47};
48
50public:
51 virtual ~StreamReader ();
52 virtual String name () const = 0;
53 virtual ssize_t read (void *buffer, size_t len) = 0;
54 virtual bool close () = 0;
55 static constexpr size_t buffer_size = 131072;
56};
57
58StreamReaderP stream_reader_from_file (const String &file);
59StreamReaderP stream_reader_zip_member (const String &archive, const String &member, Storage::StorageFlags f = Storage::AUTO_ZSTD);
60
62public:
63 virtual ~StreamWriter ();
64 virtual String name () const = 0;
65 virtual ssize_t write (const void *buffer, size_t len) = 0;
66 virtual bool close () = 0;
67 static constexpr size_t buffer_size = 131072;
68};
69
70StreamWriterP stream_writer_create_file (const String &filename, int mode = 0644);
71
73void anklang_cachedir_cleanup (const String &cachedir);
75
76} // Ase
77
78#endif // __ASE_STORAGE_HH__
static constexpr size_t buffer_size
Recommended buffer size.
Definition storage.hh:55
static constexpr size_t buffer_size
Recommended buffer size.
Definition storage.hh:67
dirname
The Anklang C++ API namespace.
Definition api.hh:9
String anklang_cachedir_create()
Create exclusive cache directory for this process' runtime.
Definition storage.cc:106
Error
Enum representing Error states.
Definition api.hh:22
void anklang_cachedir_clean_stale()
Clean stale cache directories from past runtimes, may be called from any thread.
Definition storage.cc:161
void anklang_cachedir_cleanup(const String &cachedir)
Cleanup a cachedir previously created with anklang_cachedir_create().
Definition storage.cc:142
typedef ssize_t