mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
Merge pull request #528 from chouquette/master
FileRef: Allow an IOStream to be used
This commit is contained in:
commit
c3807e59cd
@ -54,6 +54,10 @@
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
template <typename T>
|
||||
static File* createInternal(T arg, const String& filename, bool readAudioProperties,
|
||||
AudioProperties::ReadStyle audioPropertiesStyle);
|
||||
|
||||
class FileRef::FileRefPrivate : public RefCounter
|
||||
{
|
||||
public:
|
||||
@ -83,6 +87,17 @@ FileRef::FileRef(FileName fileName, bool readAudioProperties,
|
||||
d = new FileRefPrivate(create(fileName, readAudioProperties, audioPropertiesStyle));
|
||||
}
|
||||
|
||||
FileRef::FileRef(IOStream* stream, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle)
|
||||
{
|
||||
d = new FileRefPrivate(createInternal(stream,
|
||||
#ifdef _WIN32
|
||||
stream->name().toString()
|
||||
#else
|
||||
stream->name()
|
||||
#endif
|
||||
, readAudioProperties, audioPropertiesStyle));
|
||||
}
|
||||
|
||||
FileRef::FileRef(File *file)
|
||||
{
|
||||
d = new FileRefPrivate(file);
|
||||
@ -213,24 +228,25 @@ File *FileRef::create(FileName fileName, bool readAudioProperties,
|
||||
return file;
|
||||
}
|
||||
|
||||
return createInternal(fileName,
|
||||
#ifdef _WIN32
|
||||
fileName.toString()
|
||||
#else
|
||||
fileName
|
||||
#endif
|
||||
, readAudioProperties, audioPropertiesStyle);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static File* createInternal(T fileName, const String& s, bool readAudioProperties,
|
||||
AudioProperties::ReadStyle audioPropertiesStyle)
|
||||
{
|
||||
// Ok, this is really dumb for now, but it works for testing.
|
||||
|
||||
String ext;
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
String s = fileName.toString();
|
||||
|
||||
#else
|
||||
|
||||
String s = fileName;
|
||||
|
||||
#endif
|
||||
|
||||
const int pos = s.rfind(".");
|
||||
if(pos != -1)
|
||||
ext = s.substr(pos + 1).upper();
|
||||
}
|
||||
const int pos = s.rfind(".");
|
||||
if(pos != -1)
|
||||
ext = s.substr(pos + 1).upper();
|
||||
|
||||
// If this list is updated, the method defaultFileExtensions() should also be
|
||||
// updated. However at some point that list should be created at the same time
|
||||
@ -238,7 +254,7 @@ File *FileRef::create(FileName fileName, bool readAudioProperties,
|
||||
|
||||
if(!ext.isEmpty()) {
|
||||
if(ext == "MP3")
|
||||
return new MPEG::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
return new MPEG::File(fileName, ID3v2::FrameFactory::instance(), readAudioProperties, audioPropertiesStyle);
|
||||
if(ext == "OGG")
|
||||
return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
if(ext == "OGA") {
|
||||
@ -250,7 +266,7 @@ File *FileRef::create(FileName fileName, bool readAudioProperties,
|
||||
return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
}
|
||||
if(ext == "FLAC")
|
||||
return new FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
return new FLAC::File(fileName, ID3v2::FrameFactory::instance(), readAudioProperties, audioPropertiesStyle);
|
||||
if(ext == "MPC")
|
||||
return new MPC::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
if(ext == "WV")
|
||||
|
@ -128,7 +128,21 @@ namespace TagLib {
|
||||
audioPropertiesStyle = AudioProperties::Average);
|
||||
|
||||
/*!
|
||||
* Construct a FileRef using \a file. The FileRef now takes ownership of the
|
||||
* Construct a FileRef from an opened \a IOStream. If \a readAudioProperties is true then
|
||||
* the audio properties will be read using \a audioPropertiesStyle. If
|
||||
* \a readAudioProperties is false then \a audioPropertiesStyle will be
|
||||
* ignored.
|
||||
*
|
||||
* Also see the note in the class documentation about why you may not want to
|
||||
* use this method in your application.
|
||||
*/
|
||||
explicit FileRef(IOStream* stream,
|
||||
bool readAudioProperties = true,
|
||||
AudioProperties::ReadStyle
|
||||
audioPropertiesStyle = AudioProperties::Average);
|
||||
|
||||
/*!
|
||||
* Contruct a FileRef using \a file. The FileRef now takes ownership of the
|
||||
* pointer and will delete the File when it passes out of scope.
|
||||
*/
|
||||
explicit FileRef(File *file);
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <vorbisfile.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "utils.h"
|
||||
#include <tfilestream.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace TagLib;
|
||||
@ -74,6 +75,17 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(7));
|
||||
CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2080));
|
||||
delete f;
|
||||
|
||||
FileStream fs(newname.c_str());
|
||||
f = new FileRef(&fs);
|
||||
CPPUNIT_ASSERT(!f->isNull());
|
||||
CPPUNIT_ASSERT_EQUAL(f->tag()->artist(), String("ttest artist"));
|
||||
CPPUNIT_ASSERT_EQUAL(f->tag()->title(), String("ytest title"));
|
||||
CPPUNIT_ASSERT_EQUAL(f->tag()->genre(), String("uTest!"));
|
||||
CPPUNIT_ASSERT_EQUAL(f->tag()->album(), String("ialbummmm"));
|
||||
CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(7));
|
||||
CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2080));
|
||||
delete f;
|
||||
}
|
||||
|
||||
void testMusepack()
|
||||
|
Loading…
x
Reference in New Issue
Block a user