LCOV - code coverage report
Current view: top level - muse/framework/global/serialization - zipwriter.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 26 26
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : #include "zipwriter.h"
      23              : 
      24              : #include "global/io/iodevice.h"
      25              : #include "global/types/bytearray.h"
      26              : 
      27              : #include "internal/zipcontainer.h"
      28              : 
      29              : using namespace muse;
      30              : 
      31              : struct ZipWriter::Impl
      32              : {
      33              :     ZipContainer* zip = nullptr;
      34              :     bool isClosed = false;
      35              : };
      36              : 
      37            6 : ZipWriter::ZipWriter(io::IODevice* device)
      38              : {
      39            6 :     m_device = device;
      40            6 :     m_impl = new Impl();
      41            6 :     m_impl->zip = new ZipContainer(m_device);
      42            6 : }
      43              : 
      44            6 : ZipWriter::~ZipWriter()
      45              : {
      46            6 :     close();
      47            6 :     delete m_impl->zip;
      48            6 :     delete m_impl;
      49            6 : }
      50              : 
      51           23 : void ZipWriter::flush()
      52              : {
      53           23 : }
      54              : 
      55           12 : void ZipWriter::close()
      56              : {
      57           12 :     if (m_impl->isClosed) {
      58            6 :         return;
      59              :     }
      60              : 
      61            6 :     m_impl->zip->close();
      62            6 :     if (m_device) {
      63            6 :         flush();
      64            6 :         m_device->close();
      65              :     }
      66              : 
      67            6 :     m_impl->isClosed = true;
      68              : }
      69              : 
      70           17 : bool ZipWriter::hasError() const
      71              : {
      72           17 :     return m_impl->zip->status() != ZipContainer::NoError;
      73              : }
      74              : 
      75           17 : void ZipWriter::addFile(const std::string& fileName, const ByteArray& data)
      76              : {
      77           17 :     m_impl->zip->addFile(fileName, data);
      78           17 :     flush();
      79           17 : }
        

Generated by: LCOV version 2.0-1