Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Async_Reader.cpp
Go to the documentation of this file.
2
3namespace joedb
4{
5 //////////////////////////////////////////////////////////////////////////
7 //////////////////////////////////////////////////////////////////////////
8 (
9 const Abstract_File &file,
10 int64_t start,
11 int64_t end
12 ):
13 file(file),
14 end(end),
15 current(start),
16 end_of_file(false)
17 {
18 if (current > end)
19 current = end;
20 }
21
22 //////////////////////////////////////////////////////////////////////////
23 size_t Async_Reader::read(char *buffer, size_t capacity)
24 //////////////////////////////////////////////////////////////////////////
25 {
26 size_t size = size_t(end - current);
27 if (size > capacity)
28 size = capacity;
29
30 size_t total_read = 0;
31
32 while (size > 0)
33 {
34 const size_t actually_read = file.pread
35 (
36 buffer + total_read,
37 size,
38 current
39 );
40
41 if (actually_read == 0)
42 {
43 end_of_file = true;
44 break;
45 }
46 else
47 end_of_file = false;
48
49 current += int64_t(actually_read);
50 total_read += actually_read;
51 size -= actually_read;
52 }
53
54 return total_read;
55 }
56}
virtual size_t pread(char *data, size_t size, int64_t offset) const
Read a range of bytes.
Async_Reader(const Abstract_File &file, int64_t start, int64_t end)
size_t read(char *buffer, size_t capacity)
Definition Blob.h:7