kodi
TagLibVFSStream.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "filesystem/File.h"
12 
13 #include <taglib/taglib.h>
14 #include <taglib/tiostream.h>
15 
16 namespace MUSIC_INFO
17 {
18  class TagLibVFSStream : public TagLib::IOStream
19  {
20  public:
25  TagLibVFSStream(const std::string& strFileName, bool readOnly);
26 
30  ~TagLibVFSStream() override;
31 
35  TagLib::FileName name() const override;
36 
40 #if (TAGLIB_MAJOR_VERSION >= 2)
41  TagLib::ByteVector readBlock(unsigned long length) override;
42 #else
43  TagLib::ByteVector readBlock(TagLib::ulong length) override;
44 #endif
45 
55  void writeBlock(const TagLib::ByteVector &data) override;
56 
64 #if (TAGLIB_MAJOR_VERSION >= 2)
65  void insert(const TagLib::ByteVector& data,
66  TagLib::offset_t start = 0,
67  size_t replace = 0) override;
68 #else
69  void insert(const TagLib::ByteVector &data, TagLib::ulong start = 0, TagLib::ulong replace = 0) override;
70 #endif
71 
79 #if (TAGLIB_MAJOR_VERSION >= 2)
80  void removeBlock(TagLib::offset_t start = 0, size_t length = 0) override;
81 #else
82  void removeBlock(TagLib::ulong start = 0, TagLib::ulong length = 0) override;
83 #endif
84 
88  bool readOnly() const override;
89 
94  bool isOpen() const override;
95 
102  void seek(long offset, TagLib::IOStream::Position p = Beginning) override;
103 
107  void clear() override;
108 
112  long tell() const override;
113 
117  long length() override;
118 
122  void truncate(long length) override;
123 
124  protected:
128 #if (TAGLIB_MAJOR_VERSION >= 2)
129  static unsigned int bufferSize() { return 1024; }
130 #else
131  static TagLib::uint bufferSize() { return 1024; }
132 #endif
133 
134  private:
135  std::string m_strFileName;
136  XFILE::CFile m_file;
137  bool m_bIsReadOnly;
138  bool m_bIsOpen;
139  };
140 }
141 
TagLibVFSStream(const std::string &strFileName, bool readOnly)
Definition: TagLibVFSStream.cpp:25
long tell() const override
Definition: TagLibVFSStream.cpp:343
Definition: TagLibVFSStream.h:18
void removeBlock(TagLib::ulong start=0, TagLib::ulong length=0) override
Definition: TagLibVFSStream.cpp:211
void writeBlock(const TagLib::ByteVector &data) override
Definition: TagLibVFSStream.cpp:90
static TagLib::uint bufferSize()
Definition: TagLibVFSStream.h:131
void insert(const TagLib::ByteVector &data, TagLib::ulong start=0, TagLib::ulong replace=0) override
Definition: TagLibVFSStream.cpp:105
Definition: File.h:37
bool readOnly() const override
Definition: TagLibVFSStream.cpp:265
long length() override
Definition: TagLibVFSStream.cpp:355
void seek(long offset, TagLib::IOStream::Position p=Beginning) override
Definition: TagLibVFSStream.cpp:285
bool isOpen() const override
Definition: TagLibVFSStream.cpp:274
void clear() override
Definition: TagLibVFSStream.cpp:336
~TagLibVFSStream() override
Definition: TagLibVFSStream.cpp:45
TagLib::ByteVector readBlock(TagLib::ulong length) override
Definition: TagLibVFSStream.cpp:64
TagLib::FileName name() const override
Definition: TagLibVFSStream.cpp:53
void truncate(long length) override
Definition: TagLibVFSStream.cpp:363
Definition: Application.h:77