/** ** Copyright (c) 2007-2009 Illumina, Inc. ** ** This software is covered by the "Illumina Genome Analyzer Software ** License Agreement" and the "Illumina Source Code License Agreement", ** and certain third party copyright/licenses, and any user of this ** source file is bound by the terms therein (see accompanying files ** Illumina_Genome_Analyzer_Software_License_Agreement.pdf and ** Illumina_Source_Code_License_Agreement.pdf and third party ** copyright/license notices). ** ** This file is part of the Consensus Assessment of Sequence And VAriation ** (CASAVA) software package. ** ** \file FilteringStreams.cpp ** ** \brief Implementation of the I/O API for sequence data type (qseq files). ** ** \author Come Raczy **/ #include "common/FilteringStreams.hh" #include #ifdef HAVE_ZLIB # include #endif namespace casava { namespace common { Ifstream::Ifstream(const std::string &filePath, const Filter &decompress) { decompress(*this); push(boost::iostreams::file_source(filePath)); } bool Ifstream::is_open() { using boost::iostreams::file_source; return (size() > 0) && component (size() - 1) && component< file_source> (size() - 1)->is_open(); } /** * \brief Starting with boost 1.44, there is an optimization which skips writing anything into the * chain if the size of it is 0 bytes. Since the gzip_compressor needs the write to be executed at * least once, the proper header and crcs are not written and the empty files don't form a valid gzip * */ void Ofstream::preventCorruptGzipFiles() { #ifdef HAVE_ZLIB boost::iostreams::gzip_compressor *pgzComp(component(0)); if (pgzComp) { boost::iostreams::file_sink *pfs(component(1)); // second component is expected to be a file_sink. If it is not, someone has put more // stuff in the chain. Please have a check if this approach is still valid. BOOST_ASSERT(pfs); pgzComp->write(*pfs, "", 0); } #endif } Ofstream::Ofstream(const std::string &filePath, const Filter &compress, ios_base::openmode mode) { compress(*this); push(boost::iostreams::file_sink(filePath, mode)); preventCorruptGzipFiles(); } Ofstream::Ofstream(const Filter &compress) { compress(*this); } void Ofstream::open(const std::string &filePath, ios_base::openmode mode) { push(boost::iostreams::file_sink(filePath, mode)); preventCorruptGzipFiles(); } void Ofstream::close() { pop(); } bool Ofstream::is_open() { using boost::iostreams::file_sink; return (size() > 0) && component (size() - 1) && component< file_sink> (size() - 1)->is_open(); } } // namespace common } // namespace casava