]>
git.saurik.com Git - wxWidgets.git/blob - src/common/zipstream.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: input stream for ZIP archive access
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "zipstream.h"
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
20 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
24 #include "wx/stream.h"
25 #include "wx/wfstream.h"
26 #include "wx/zipstream.h"
29 wxZipInputStream::wxZipInputStream(const wxString
& archive
, const wxString
& file
) : wxInputStream()
35 m_Archive
= (void*) unzOpen(archive
.mb_str(wxConvFile
));
36 if (m_Archive
== NULL
)
38 m_lasterror
= wxStream_READ_ERR
;
41 if (unzLocateFile((unzFile
)m_Archive
, file
.mb_str(wxConvFile
), 0) != UNZ_OK
)
43 m_lasterror
= wxStream_READ_ERR
;
47 unzGetCurrentFileInfo((unzFile
)m_Archive
, &zinfo
, (char*) NULL
, 0, (void*) NULL
, 0, (char*) NULL
, 0);
49 if (unzOpenCurrentFile((unzFile
)m_Archive
) != UNZ_OK
)
51 m_lasterror
= wxStream_READ_ERR
;
54 m_Size
= zinfo
.uncompressed_size
;
59 wxZipInputStream::~wxZipInputStream()
64 unzCloseCurrentFile((unzFile
)m_Archive
);
65 unzClose((unzFile
)m_Archive
);
71 size_t wxZipInputStream::OnSysRead(void *buffer
, size_t bufsize
)
73 if (m_Pos
+ bufsize
> m_Size
) bufsize
= m_Size
- m_Pos
;
74 unzReadCurrentFile((unzFile
)m_Archive
, buffer
, bufsize
);
81 off_t
wxZipInputStream::OnSysSeek(off_t seek
, wxSeekMode mode
)
88 case wxFromCurrent
: nextpos
= seek
+ m_Pos
; break;
89 case wxFromStart
: nextpos
= seek
; break;
90 case wxFromEnd
: nextpos
= m_Size
- 1 + seek
; break;
91 default : nextpos
= m_Pos
; break; /* just to fool compiler, never happens */
97 buf
= malloc(nextpos
- m_Pos
);
98 unzReadCurrentFile((unzFile
)m_Archive
, buf
, nextpos
- m_Pos
);
101 else if (nextpos
< m_Pos
) {
102 unzCloseCurrentFile((unzFile
)m_Archive
);
103 if (unzOpenCurrentFile((unzFile
)m_Archive
) != UNZ_OK
)
105 m_lasterror
= wxStream_READ_ERR
;
108 buf
= malloc(nextpos
);
109 unzReadCurrentFile((unzFile
)m_Archive
, buf
, nextpos
);
118 // wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB