forked from nu774/qaac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
taglibhelper.h
72 lines (67 loc) · 2.1 KB
/
taglibhelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <taglib/tiostream.h>
#include "win32util.h"
namespace TagLibX {
using TagLib::FileName;
using TagLib::ByteVector;
using TagLib::uint;
using TagLib::ulong;
class NotImplemented: public std::runtime_error {
public:
NotImplemented():
std::runtime_error("Not implemented") {}
NotImplemented(const std::string &msg):
std::runtime_error(msg + ": Not implemented") {}
};
class FDIOStreamReader: public TagLib::IOStream {
int m_fd;
public:
FDIOStreamReader(int fd): m_fd(fd) {}
FileName name() const { return "Dummy"; }
ByteVector readBlock(ulong length)
{
ByteVector v(static_cast<uint>(length));
int n = util::nread(m_fd, v.data(), length);
v.resize(std::max(0, n));
return v;
}
void writeBlock(const ByteVector &data)
{
throw NotImplemented("writeBlock");
}
void insert(const ByteVector &data, ulong start, ulong replace)
{
throw NotImplemented("insert");
}
void removeBlock(ulong start=0, ulong length=0)
{
throw NotImplemented("removeBlock");
}
bool readOnly() const { return true; }
bool isOpen() const { return true; }
void seek(long offset, IOStream::Position p = Beginning)
{
lseek(m_fd, offset, p);
}
void clear() { }
long tell() const
{
int64_t n = lseek(m_fd, 0, SEEK_CUR);
if (n > 0xffffffffLL)
throw std::runtime_error("File position exceeded "
"the limit of TagLib");
return n;
}
long length()
{
int64_t n = win32::filelengthi64(m_fd);
if (n > 0xffffffffLL)
throw std::runtime_error("File size exceeded "
"the limit of TagLib");
return n;
}
void truncate(long length)
{
throw NotImplemented("truncate");
}
};
}