]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/packsource.cpp
Use IO::Slice to constrain access to logical files
[libs/datafile.git] / source / packsource.cpp
index d054e1d4ee9e50ef99c8d9c136aee978237113bf..d22c7dc4235990591fffbf7c9d2dafba0eca3aaa 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/io/slice.h>
 #include <msp/strings/format.h>
 #include <msp/strings/regex.h>
 #include "collection.h"
@@ -5,6 +6,15 @@
 
 using namespace std;
 
+namespace {
+
+void delete_io(Msp::IO::Base *io)
+{
+       delete io;
+}
+
+}
+
 namespace Msp {
 namespace DataFile {
 
@@ -120,9 +130,10 @@ PackSource::File::File(const Pack &p, const string &fn):
 
 RefPtr<IO::Base> PackSource::File::open() const
 {
-       RefPtr<IO::BufferedFile> io_file = new IO::BufferedFile(pack.get_filename());
-       io_file->seek(pack.get_base_offset()+offset, IO::S_BEG);
-       return io_file;
+       IO::BufferedFile *io_file = new IO::BufferedFile(pack.get_filename());
+       IO::Slice *io_slice = new IO::Slice(*io_file, pack.get_base_offset()+offset, length);
+       io_slice->signal_deleted.connect(sigc::bind(sigc::ptr_fun(delete_io), io_file));
+       return io_slice;
 }
 
 string PackSource::File::get_full_name() const