This file is indexed.

/usr/include/gdcm-2.6/zipstreamimpl.h is in libgdcm2-dev 2.6.6-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
zipstream Library License:
--------------------------

The zlib/libpng License Copyright (c) 2003 Jonathan de Halleux.

This software is provided 'as-is', without any express or implied warranty. In
no event will the authors be held liable for any damages arising from the use
of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim
   that you wrote the original software. If you use this software in a
   product, an acknowledgment in the product documentation would be
   appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution

Author: Jonathan de Halleux, dehalleux@pelikhan.com, 2003

Altered by: Andreas Zieringer 2003 for OpenSG project
            made it platform independent, gzip conform, fixed gzip footer

Altered by: Geoffrey Hutchison 2005 for Open Babel project
            minor namespace modifications, VC++ compatibility

Altered by: Mathieu Malaterre 2008, for GDCM project
            when reading deflate bit stream in DICOM special handling of \0 is needed
            also when writing deflate back to disk, the add_footer must be called
*/

/*
Code is from:

http://www.codeproject.com/KB/stl/zipstream.aspx

 TODO:

zran.c
    index a zlib or gzip stream and randomly access it
    - illustrates the use of Z_BLOCK, inflatePrime(), and
      inflateSetDictionary() to provide random access

  So I might after all be able to implement seeking :)
*/
#ifndef _ZIPSTREAM_H_
#define _ZIPSTREAM_H_

#include <vector>
#include <string>
#include <streambuf>
#include <sstream>
#include <iostream>
#include <algorithm>

#include <string.h> // memcpy
#include <stdio.h> // EOF

#include <gdcm_zlib.h>

#ifdef WIN32 /* Window 95 & Windows NT */
#  define OS_CODE  0x0b
#endif
#if defined(MACOS) || defined(TARGET_OS_MAC)
#  define OS_CODE  0x07
#endif
#ifndef OS_CODE
#  define OS_CODE  0x03  /* assume Unix */
#endif

namespace zlib_stream {

namespace detail
{
    const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */

    /* gzip flag byte */
    const int gz_ascii_flag =  0x01; /* bit 0 set: file probably ascii text */
    const int gz_head_crc    = 0x02; /* bit 1 set: header CRC present */
    const int gz_extra_field = 0x04; /* bit 2 set: extra field present */
    const int gz_orig_name  =  0x08; /* bit 3 set: original file name present */
    const int gz_comment    =  0x10; /* bit 4 set: file comment present */
    const int gz_reserved   =  0xE0; /* bits 5..7: reserved */
}

/// default gzip buffer size,
/// change this to suite your needs
const size_t zstream_default_buffer_size = 4096;

/// Compression strategy, see zlib doc.
enum EStrategy
{
    StrategyFiltered = 1,
    StrategyHuffmanOnly = 2,
    DefaultStrategy = 0
};

//*****************************************************************************
//  template class basic_zip_streambuf
//*****************************************************************************

/** \brief A stream decorator that takes raw input and zips it to a ostream.

The class wraps up the inflate method of the zlib library 1.1.4 http://www.gzip.org/zlib/
*/
template <class charT,
          class traits = std::char_traits<charT> >
class basic_zip_streambuf : public std::basic_streambuf<charT, traits>
{
public:
    typedef std::basic_ostream<charT, traits>& ostream_reference;
    typedef unsigned char byte_type;
    typedef char          char_type;
    typedef byte_type* byte_buffer_type;
    typedef std::vector<byte_type> byte_vector_type;
    typedef std::vector<char_type> char_vector_type;
    typedef int int_type;

    basic_zip_streambuf(ostream_reference ostream,
                            int level,
                            EStrategy strategy,
                            int window_size,
                            int memory_level,
                            size_t buffer_size);

    ~basic_zip_streambuf(void);

    int               sync        (void);
    int_type          overflow    (int_type c);
    std::streamsize   flush       (void);
    inline
    ostream_reference get_ostream (void) const;
    inline
    int               get_zerr    (void) const;
    inline
    unsigned long     get_crc     (void) const;
    inline
    unsigned long     get_in_size (void) const;
    inline
    long              get_out_size(void) const;

private:

    bool              zip_to_stream(char_type *buffer,
                                    std::streamsize buffer_size);

    ostream_reference   _ostream;
    z_stream            _zip_stream;
    int                 _err;
    byte_vector_type    _output_buffer;
    char_vector_type    _buffer;
    unsigned long       _crc;
};


//*****************************************************************************
//  template class basic_unzip_streambuf
//*****************************************************************************

/** \brief A stream decorator that takes compressed input and unzips it to a istream.

The class wraps up the deflate method of the zlib library 1.1.4 http://www.gzip.org/zlib/
*/
template <class charT,
          class traits = std::char_traits<charT> >
class basic_unzip_streambuf :
    public std::basic_streambuf<charT, traits>
{
public:
    typedef std::basic_istream<charT,traits>& istream_reference;
    typedef unsigned char byte_type;
    typedef charT          char_type;
    typedef byte_type* byte_buffer_type;
    typedef std::vector<byte_type> byte_vector_type;
    typedef std::vector<char_type> char_vector_type;
    typedef int int_type;

    /** Construct a unzip stream
     * More info on the following parameters can be found in the zlib documentation.
     */
    basic_unzip_streambuf(istream_reference istream,
                          int window_size,
                          size_t read_buffer_size,
                          size_t input_buffer_size);

    ~basic_unzip_streambuf(void);

    int_type underflow(void);

    /// returns the compressed input istream
    inline
    istream_reference get_istream              (void);
    inline
    z_stream&         get_zip_stream           (void);
    inline
    int               get_zerr                 (void) const;
    inline
    unsigned long     get_crc                  (void) const;
    inline
    long              get_out_size             (void) const;
    inline
    long              get_in_size              (void) const;


private:

    void              put_back_from_zip_stream (void);

    std::streamsize   unzip_from_stream        (char_type* buffer,
                                                std::streamsize buffer_size);

    size_t            fill_input_buffer        (void);

    istream_reference   _istream;
    z_stream            _zip_stream;
    int                 _err;
    byte_vector_type    _input_buffer;
    char_vector_type    _buffer;
    unsigned long       _crc;
};

//*****************************************************************************
//  template class basic_zip_ostream
//*****************************************************************************

template <class charT,
          class traits = std::char_traits<charT> >
class basic_zip_ostream :
    public basic_zip_streambuf<charT, traits>,
    public std::basic_ostream<charT, traits>
{
public:

    typedef char char_type;
    typedef std::basic_ostream<charT, traits>& ostream_reference;
    typedef std::basic_ostream<charT, traits> ostream_type;

    inline
    explicit basic_zip_ostream(ostream_reference ostream,
                               bool is_gzip = false,
                               int level = Z_DEFAULT_COMPRESSION,
                               EStrategy strategy = DefaultStrategy,
                               int window_size = -15 /*windowBits is passed < 0 to suppress zlib header */,
                               int memory_level = 8,
                               size_t buffer_size = zstream_default_buffer_size);

    ~basic_zip_ostream(void);

    inline
    bool                              is_gzip   (void) const;
    inline
    basic_zip_ostream<charT, traits>& zflush    (void);
    void                              finished  (void);

//    void                              make_gzip()
//       { add_header(); _is_gzip = true; }

private:

    basic_zip_ostream<charT,traits>&  add_header(void);
    basic_zip_ostream<charT,traits>&  add_footer(void);

    bool _is_gzip;
    bool _added_footer;
};

//*****************************************************************************
//  template class basic_zip_istream
//*****************************************************************************

template <class charT,
          class traits = std::char_traits<charT> >
class basic_zip_istream :
    public basic_unzip_streambuf<charT, traits>,
    public std::basic_istream<charT, traits>
{
public:
    typedef std::basic_istream<charT, traits>& istream_reference;
    typedef std::basic_istream<charT, traits> istream_type;

    explicit basic_zip_istream(istream_reference istream,
                               int window_size = -15 /*windowBits is passed < 0 to suppress zlib header */,
                               size_t read_buffer_size = zstream_default_buffer_size,
                               size_t input_buffer_size = zstream_default_buffer_size);

    inline
    bool     is_gzip           (void) const;
    inline
    bool     check_crc         (void);
    inline
    bool     check_data_size   (void) const;
    inline
    long     get_gzip_crc      (void) const;
    inline
    long     get_gzip_data_size(void) const;

protected:

    int      check_header      (void);
    void     read_footer       (void);

    bool _is_gzip;
    long _gzip_crc;
    long _gzip_data_size;
};

/// A typedef for basic_zip_ostream<char>
typedef basic_zip_ostream<char> zip_ostream;
/// A typedef for basic_zip_istream<char>
typedef basic_zip_istream<char> zip_istream;

/// A typedef for basic_zip_ostream<wchar_t>
//typedef basic_zip_ostream<wchar_t> zip_wostream;
/// A typedef for basic_zip_istream<wchart>
//typedef basic_zip_istream<wchar_t> zip_wistream;

//! Helper function to check whether stream is compressed or not.
inline bool isGZip(std::istream &is)
{
    const int gz_magic[2] = {0x1f, 0x8b};

    int c1 = is.get();
    if(c1 != gz_magic[0])
    {
        is.putback((char)c1);
        return false;
    }

    int c2 = is.get();
    if(c2 != gz_magic[1])
    {
        is.putback((char)c2);
        is.putback((char)c1);
        return false;
    }

    is.putback((char)c2);
    is.putback((char)c1);
    return true;
}

#include "zipstreamimpl.hpp"

}

#endif // _ZIPSTREAM_H_