From e5289623539d2bd64d4276551a968cf1a9f8e793 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 12 Jun 2019 19:42:25 +0300 Subject: [PATCH] Use IO::BufferedFile in the packer component of datatool --- tool/packer.cpp | 11 +++-------- tool/packer.h | 5 ++--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tool/packer.cpp b/tool/packer.cpp index 56dfa03..d54d333 100644 --- a/tool/packer.cpp +++ b/tool/packer.cpp @@ -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; diff --git a/tool/packer.h b/tool/packer.h index 913d7d6..960fea6 100644 --- a/tool/packer.h +++ b/tool/packer.h @@ -20,15 +20,14 @@ private: typedef std::list ObjectList; DataTool &tool; - Msp::IO::File *tmp_file; - Msp::IO::Buffered *tmp_buf; + Msp::IO::BufferedFile *tmp_file; std::list directory; unsigned dir_alloc; public: Packer(DataTool &); private: - static Msp::IO::File *tempfile(); + static Msp::IO::BufferedFile *tempfile(); public: ~Packer(); -- 2.43.0