~ubuntu-branches/debian/jessie/ugene/jessie

« back to all changes in this revision

Viewing changes to src/corelibs/U2Core/src/io/ZlibAdapter.h

  • Committer: Package Import Robot
  • Author(s): Steffen Moeller
  • Date: 2011-11-02 13:29:07 UTC
  • mfrom: (1.2.1) (3.1.11 natty)
  • Revision ID: package-import@ubuntu.com-20111102132907-o34gwnt0uj5g6hen
Tags: 1.9.8+repack-1
* First release to Debian
  - added README.Debian
  - increased policy version to 3.9.2
  - added URLs for version control system
* Added debug package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * UGENE - Integrated Bioinformatics Tools.
 
3
 * Copyright (C) 2008-2011 UniPro <ugene@unipro.ru>
 
4
 * http://ugene.unipro.ru
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; either version 2
 
9
 * of the License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
19
 * MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#ifndef _U2_ZLIB_ADAPTER_H_
 
23
#define _U2_ZLIB_ADAPTER_H_
 
24
 
 
25
#include <U2Core/IOAdapter.h>
 
26
#include "RingBuffer.h"
 
27
 
 
28
namespace U2 {
 
29
 
 
30
class GzipUtil;
 
31
struct GZipIndex;
 
32
struct GZipIndexAccessPoint;
 
33
 
 
34
class U2CORE_EXPORT ZlibAdapter: public IOAdapter {
 
35
    Q_OBJECT
 
36
public:
 
37
    ZlibAdapter(IOAdapter* io);
 
38
    ~ZlibAdapter();
 
39
    
 
40
    virtual bool open(const GUrl& url, IOAdapterMode m_ );
 
41
 
 
42
    virtual bool isOpen() const {return io->isOpen();}
 
43
 
 
44
    virtual void close();
 
45
 
 
46
    virtual qint64 readBlock(char* data, qint64 maxSize);
 
47
 
 
48
    virtual qint64 writeBlock(const char* data, qint64 size);
 
49
 
 
50
    virtual bool skip(qint64 nBytes);
 
51
    
 
52
    virtual qint64 left() const {return -1;}
 
53
 
 
54
    virtual int getProgress() const {return io->getProgress();}
 
55
    
 
56
    virtual qint64 bytesRead() const;
 
57
    
 
58
    virtual GUrl getURL() const;
 
59
 
 
60
    /**
 
61
     * should be invoked after open() ( needs z not null )
 
62
     */
 
63
    bool skip( const GZipIndexAccessPoint& point, qint64 offset );
 
64
    
 
65
    /**
 
66
     *on error *ok set to false and GZipIndex() is returned
 
67
     * io - opened ioadapter, on the beginning of the file
 
68
     */
 
69
    static GZipIndex buildGzipIndex( IOAdapter* io, qint64 span, bool* ok = NULL );
 
70
 
 
71
    /**
 
72
     * returns -1 if a file is failed to open
 
73
     */
 
74
    static qint64 getUncompressedFileSizeInBytes(const GUrl &url);
 
75
    
 
76
private:
 
77
    static const int BUFLEN = 32768;
 
78
    IOAdapter* io;
 
79
    GzipUtil* z;
 
80
    RingBuffer* buf; // seek buffer
 
81
    int rewinded; // how much should read from seek buffer
 
82
};
 
83
 
 
84
struct GZipIndexAccessPoint {
 
85
    qint64     out;    // corresponding offset in uncompressed data
 
86
    qint64     in;     // offset in input file of first full byte
 
87
    int        bits;   // number of bits (1-7) from byte at in - 1, or 0
 
88
    QByteArray window; //preceding WINSIZE of uncompressed data
 
89
};
 
90
 
 
91
struct U2CORE_EXPORT GZipIndex {
 
92
    static const int    WINSIZE = 32768;
 
93
    static const qint64 SPAN    = 1048576L;
 
94
    static const int    CHUNK   = 16384;
 
95
    
 
96
    QList< GZipIndexAccessPoint > points;
 
97
}; // GZipIndex
 
98
 
 
99
};//namespace
 
100
 
 
101
#endif