encode method
Implementation
List<int> encode(MetadataV2p4Body data) {
int start = 0;
final idBytes = _output.sublist(start, start + 3);
if (isoCodec.decode(idBytes) == 'ID3') {
start += 3;
_deepDecode(start, data);
} else {
// Search end of file
// Maybe there exists id3v1, so we should first search for ID3v1
int outputLength = _output.length;
start = outputLength - 128;
if (start > 0 &&
isoCodec.decode(_output.sublist(start, start + 3)) == 'TAG') {
// exist ID3v1
start -= 10;
} else {
start = outputLength - 10;
}
if (start > 0 &&
isoCodec.decode(_output.sublist(start, start + 3)) == '3DI') {
start += 3;
// exist footer, find the `start` of id3v2.4
start = _decodeFooterReturnFixStart(start);
// subtract 3 bytes of ‘ID3’
start += 3;
_deepDecode(start, data);
} else {
start = 0;
final insertBytes = _createNewID3Body(start, data);
_output.insertAll(0, insertBytes);
}
}
return _output;
}