mirror of
https://github.com/taglib/taglib.git
synced 2025-11-03 08:15:50 -05:00
Untested chunk writing code.
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@808237 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
@ -23,8 +23,12 @@
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tbytevector.h>
|
||||
#include <tdebug.h>
|
||||
#include <tstring.h>
|
||||
|
||||
#include "rifffile.h"
|
||||
#include <tbytevectorlist.h>
|
||||
#include <vector>
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
@ -42,9 +46,9 @@ public:
|
||||
uint size;
|
||||
ByteVector format;
|
||||
|
||||
ByteVectorList chunkNames;
|
||||
List<uint> chunkOffsets;
|
||||
List<uint> chunkSizes;
|
||||
std::vector<ByteVector> chunkNames;
|
||||
std::vector<uint> chunkOffsets;
|
||||
std::vector<uint> chunkSizes;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -104,6 +108,39 @@ ByteVector RIFF::File::chunkData(uint i)
|
||||
return readBlock(d->chunkSizes[i]);
|
||||
}
|
||||
|
||||
void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data)
|
||||
{
|
||||
if(d->chunkNames.size() == 0)
|
||||
{
|
||||
debug("RIFF::File::setChunkData - No valid chunks found.");
|
||||
return;
|
||||
}
|
||||
|
||||
for(uint i = 0; i < d->chunkNames.size(); i++) {
|
||||
if(d->chunkNames[i] == name) {
|
||||
|
||||
int sizeDifference = data.size() - d->chunkSizes[i];
|
||||
|
||||
// First we update the global size
|
||||
|
||||
insert(ByteVector::fromUInt(d->size + sizeDifference, d->endianness == BigEndian), 4, 4);
|
||||
|
||||
// Now update the specific chunk
|
||||
|
||||
writeChunk(name, data, d->chunkOffsets[i] - 8, d->chunkOffsets[i] + 8);
|
||||
|
||||
// Now update the internal offsets
|
||||
|
||||
for(i++; i < d->chunkNames.size(); i++)
|
||||
d->chunkOffsets[i] += sizeDifference;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
debug("Could not find chunk.");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -120,11 +157,20 @@ void RIFF::File::read()
|
||||
ByteVector chunkName = readBlock(4);
|
||||
uint chunkSize = readBlock(4).toUInt(bigEndian);
|
||||
|
||||
d->chunkNames.append(chunkName);
|
||||
d->chunkSizes.append(chunkSize);
|
||||
d->chunkNames.push_back(chunkName);
|
||||
d->chunkSizes.push_back(chunkSize);
|
||||
|
||||
d->chunkOffsets.append(tell());
|
||||
d->chunkOffsets.push_back(tell());
|
||||
|
||||
seek(chunkSize, Current);
|
||||
}
|
||||
}
|
||||
|
||||
void RIFF::File::writeChunk(const ByteVector &name, const ByteVector &data,
|
||||
ulong offset, ulong replace)
|
||||
{
|
||||
ByteVector value = name;
|
||||
value.append(ByteVector::fromUInt(data.size(), d->endianness == BigEndian));
|
||||
value.append(data);
|
||||
insert(data, offset, replace);
|
||||
}
|
||||
|
||||
@ -93,6 +93,8 @@ namespace TagLib {
|
||||
File &operator=(const File &);
|
||||
|
||||
void read();
|
||||
void writeChunk(const ByteVector &name, const ByteVector &data,
|
||||
ulong offset, ulong replace = 0);
|
||||
|
||||
class FilePrivate;
|
||||
FilePrivate *d;
|
||||
|
||||
Reference in New Issue
Block a user