]> git.tdb.fi Git - libs/datafile.git/commitdiff
Use IO::BufferedFile in the packer component of datatool
authorMikko Rasa <tdb@tdb.fi>
Wed, 12 Jun 2019 16:42:25 +0000 (19:42 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 12 Jun 2019 17:05:50 +0000 (20:05 +0300)
tool/packer.cpp
tool/packer.h

index 56dfa0334fb3a93fecad03f77a6a763cb3fb39c1..d54d333e3affc244e80ce9653cbc4867f66f43fe 100644 (file)
@@ -13,11 +13,10 @@ using namespace Msp;
 Packer::Packer(DataTool &t):
        tool(t),
        tmp_file(tempfile()),
-       tmp_buf(new IO::Buffered(*tmp_file)),
        dir_alloc(0)
 { }
 
-IO::File *Packer::tempfile()
+IO::BufferedFile *Packer::tempfile()
 {
        FS::Path tmpdir;
        const char *tmp_env = getenv("TMPDIR");
@@ -31,7 +30,7 @@ IO::File *Packer::tempfile()
                try
                {
                        FS::Path filename = tmpdir/format("mspdatatool.%d", i);
-                       IO::File *file = new IO::File(filename.str(), IO::M_RDWR, IO::File::C_NEW);
+                       IO::BufferedFile *file = new IO::BufferedFile(filename.str(), IO::M_RDWR, IO::File::C_NEW);
                        FS::unlink(filename.str());
                        return file;
                }
@@ -44,7 +43,6 @@ IO::File *Packer::tempfile()
 
 Packer::~Packer()
 {
-       delete tmp_buf;
        delete tmp_file;
 }
 
@@ -61,10 +59,7 @@ void Packer::pack_file(const string &fn)
        if(raw)
                transfer_raw(in, *tmp_file);
        else
-       {
-               transfer_datafile(in, fn, *tmp_buf, objects);
-               tmp_buf->flush();
-       }
+               transfer_datafile(in, fn, *tmp_file, objects);
 
        unsigned length = tmp_file->tell()-offset;
 
index 913d7d6825bc30fd6ba58cf94c2e463d8efb880b..960fea6f391a2b49fd7420af193b069d4bdd66f3 100644 (file)
@@ -20,15 +20,14 @@ private:
        typedef std::list<Object> ObjectList;
 
        DataTool &tool;
-       Msp::IO::File *tmp_file;
-       Msp::IO::Buffered *tmp_buf;
+       Msp::IO::BufferedFile *tmp_file;
        std::list<Msp::DataFile::Statement> directory;
        unsigned dir_alloc;
 
 public:
        Packer(DataTool &);
 private:
-       static Msp::IO::File *tempfile();
+       static Msp::IO::BufferedFile *tempfile();
 public:
        ~Packer();