]>
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
13 #include <wx/wxprec.h>
23 #if wxUSE_ZLIB && wxUSE_STREAMS && wxUSE_ZIPSTREAM
25 #include <wx/stream.h>
26 #include <wx/wfstream.h>
27 #include <wx/zipstream.h>
33 wxZipInputStream::wxZipInputStream(const wxString
& archive
, const wxString
& file
) : wxInputStream()
39 m_Archive
= (void*) unzOpen(archive
);
40 if (m_Archive
== NULL
) {
41 m_lasterror
= wxStream_READ_ERR
;
44 if (unzLocateFile((unzFile
)m_Archive
, file
, 0) != UNZ_OK
) {
45 m_lasterror
= wxStream_READ_ERR
;
48 unzGetCurrentFileInfo((unzFile
)m_Archive
, &zinfo
, NULL
, 0, NULL
, 0, NULL
, 0);
50 if (unzOpenCurrentFile((unzFile
)m_Archive
) != UNZ_OK
) {
51 m_lasterror
= wxStream_READ_ERR
;
54 m_Size
= zinfo
.uncompressed_size
;
59 wxZipInputStream::~wxZipInputStream()
63 unzCloseCurrentFile((unzFile
)m_Archive
);
64 unzClose((unzFile
)m_Archive
);
70 size_t wxZipInputStream::OnSysRead(void *buffer
, size_t bufsize
)
72 if (m_Pos
+ bufsize
> m_Size
) bufsize
= m_Size
- m_Pos
;
73 unzReadCurrentFile((unzFile
)m_Archive
, buffer
, bufsize
);
80 off_t
wxZipInputStream::OnSysSeek(off_t seek
, wxSeekMode mode
)
86 case wxFromCurrent
: nextpos
= seek
+ m_Pos
; break;
87 case wxFromStart
: nextpos
= seek
; break;
88 case wxFromEnd
: nextpos
= m_Size
- 1 + seek
; break;
89 default : nextpos
= m_Pos
; break; /* just to fool compiler, never happens */
93 if (nextpos
> m_Pos
) {
94 buf
= malloc(nextpos
- m_Pos
);
95 unzReadCurrentFile((unzFile
)m_Archive
, buf
, nextpos
- m_Pos
);
98 else if (nextpos
< m_Pos
) {
99 unzCloseCurrentFile((unzFile
)m_Archive
);
100 if (unzOpenCurrentFile((unzFile
)m_Archive
) != UNZ_OK
) {
101 m_lasterror
= wxStream_READ_ERR
;
104 buf
= malloc(nextpos
);
105 unzReadCurrentFile((unzFile
)m_Archive
, buf
, nextpos
);