libodsstream
Library for mass spectrometry
Loading...
Searching...
No Matches
ziptsvoutputstream.cpp
Go to the documentation of this file.
1/**
2 * \file src/ziptsvoutputstream.cpp
3 * \date 27/6/2022
4 * \author Olivier Langella
5 * \brief write TSV files in a zip archive
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2022 Olivier Langella <Olivier.Langella@u-psud.fr>.
10 *
11 * This file is part of libodsstream.
12 *
13 * libodsstream is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * libodsstream is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with libodsstream. If not, see <http://www.gnu.org/licenses/>.
25 *
26 ******************************************************************************/
27
28#include "ziptsvoutputstream.h"
29#include "odsexception.h"
30#include <QTextStream>
31#include <QDebug>
32#include <quacrc32.h>
33
34ZipTsvOutputStream::ZipTsvOutputStream(const QString &zipfilename)
36{
37
38 qDebug();
39 mpa_fileZipArchive = new QFile(zipfilename);
40
41 if(mpa_fileZipArchive->open(QIODevice::WriteOnly))
42 {
43 }
44 else
45 {
46 throw OdsException(
47 QString("unable to write into ZIP file %1")
48 .arg(QFileInfo(*mpa_fileZipArchive).absoluteFilePath()));
49 }
50
51 qDebug();
52 mpa_quaZip = new QuaZip(mpa_fileZipArchive);
53 bool open_ok = mpa_quaZip->open(QuaZip::mdCreate);
54
55 if(open_ok == false)
56 {
57 throw OdsException(QObject::tr("error opening ZIP file."));
58 }
59
60 //_p_writer = new QXmlStreamWriter(&outFile);
61 qDebug();
62}
63
64
66{
67 qDebug();
69 close();
70 qDebug();
71}
72
73void
75{
76
77 qDebug();
78
81 if(mpa_quaZip != nullptr)
82 {
83 qDebug();
84 mpa_quaZip->close();
85 delete mpa_quaZip;
86 mpa_quaZip = nullptr;
87 }
88 if(mpa_fileZipArchive != nullptr)
89 {
90 qDebug();
91 mpa_fileZipArchive->close();
92 delete mpa_fileZipArchive;
93 mpa_fileZipArchive = nullptr;
94 }
95 qDebug();
96}
97
98
99void
101{
102
103 qDebug();
104 if(mpa_outFileInZip != nullptr)
105 {
106 qDebug();
107 if(mpa_otxtstream != nullptr)
108 {
109 mpa_otxtstream->flush();
110 }
111 mpa_outFileInZip->close();
112 qDebug();
113 delete mpa_outFileInZip;
114 mpa_outFileInZip = nullptr;
115 qDebug();
116 }
117 qDebug();
118}
119
120
121void
122ZipTsvOutputStream::writeSheet(const QString &sheetName)
123{
124
125 qDebug();
127 if(mpa_outFileInZip == nullptr)
128 {
129 mpa_outFileInZip = new QuaZipFile(mpa_quaZip);
130 QuaZipNewInfo info(QString("%1.tsv").arg(sheetName));
131 info.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner |
132 QFileDevice::ReadGroup);
133
134 if(mpa_outFileInZip->open(QIODevice::WriteOnly, info))
135 {
136 mpa_otxtstream = new QTextStream(mpa_outFileInZip);
137 }
138 else
139 {
140 throw OdsException(
141 QString("unable to write into file %1 new sheet %2")
142 .arg(QFileInfo(*mpa_fileZipArchive).absoluteFilePath())
143 .arg(sheetName));
144 }
145 }
146 else
147 {
148 throw OdsException(QString("mpa_outFileInZip == nullptr"));
149 }
151 qDebug();
152}
QTextStream * mpa_otxtstream
virtual void close() override
ZipTsvOutputStream(const QString &zipfilename)
QuaZipFile * mpa_outFileInZip
virtual void writeSheet(const QString &sheetName) override
open a new sheet