Anklang-0.3.0.dev956+gd75ac925 anklang-0.3.0.dev956+gd75ac925
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#pragma once
3
4#include <ase/defs.hh>
5
6namespace Ase {
7
8class Storage {
9protected:
10 virtual ~Storage () = 0;
11public:
12 enum StorageFlags {
13 NONE = 0,
14 AUTO_ZSTD = 1,
15 };
16};
17
18class StorageWriter : public Storage {
19 class Impl;
21public:
22 explicit StorageWriter (StorageFlags = StorageFlags::NONE);
23 virtual ~StorageWriter ();
24 // Writer API
25 Error open_for_writing (const String &filename);
26 Error open_with_mimetype (const String &filename, const String &mimetype);
27 Error store_file_data (const String &filename, const String &buffer, bool alwayscompress = false);
28 Error store_file (const String &filename, const String &ondiskpath, bool maycompress = true);
29 Error close ();
30 Error remove_opened ();
31};
32
33class StorageReader : public Storage {
34 class Impl;
36public:
37 explicit StorageReader (StorageFlags = StorageFlags::NONE);
38 virtual ~StorageReader ();
39 // Reader API
40 Error open_for_reading (const String &filename);
41 void search_dir (const String &dirname);
42 bool has_file (const String &filename);
43 StringS list_files ();
44 String stringread (const String &filename, ssize_t maxlength = -1);
45 Error close ();
46};
47
49public:
50 virtual ~StreamReader ();
51 virtual String name () const = 0;
52 virtual ssize_t read (void *buffer, size_t len) = 0;
53 virtual bool close () = 0;
54 static constexpr size_t buffer_size = 131072;
55};
56
57StreamReaderP stream_reader_from_file (const String &file);
58StreamReaderP stream_reader_zip_member (const String &archive, const String &member, Storage::StorageFlags f = Storage::AUTO_ZSTD);
59
61public:
62 virtual ~StreamWriter ();
63 virtual String name () const = 0;
64 virtual ssize_t write (const void *buffer, size_t len) = 0;
65 virtual bool close () = 0;
66 static constexpr size_t buffer_size = 131072;
67};
68
69StreamWriterP stream_writer_create_file (const String &filename, int mode = 0644);
70
72void anklang_cachedir_cleanup (const String &cachedir);
74
75} // Ase
76
static constexpr size_t buffer_size
Recommended buffer size.
Definition storage.hh:54
static constexpr size_t buffer_size
Recommended buffer size.
Definition storage.hh:66
dirname
The Anklang C++ API namespace.
Definition api.hh:8
String anklang_cachedir_create()
Create exclusive cache directory for this process' runtime.
Definition storage.cc:106
Error
Enum representing Error states.
Definition api.hh:21
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