@@ -38,7 +38,7 @@ private val FILE_EXTRA64 = byteArrayOfInts(0x01, 0x00)
3838 */
3939private const val DOSTIME_BEFORE_1980 = (1 shl 21 ) or (1 shl 16 )
4040
41- class ZipReader (context : Context , archiveUri : Uri ) {
41+ class ZipReader (context : Context , archiveUri : Uri , failOnUnsupported : Boolean = false ) {
4242 val records = ArrayList <ZipRecord >()
4343 val allNotCompressed: Boolean
4444
@@ -84,7 +84,8 @@ class ZipReader(context: Context, archiveUri: Uri) {
8484 it.skip(8 ) // ECDR size
8585 it.skip(2 ) // Version (creator)
8686 val versionViewer = it.readUShortLe()
87- if (versionViewer > 50u ) throw UnsupportedOperationException (" ZIP version not supported : $versionViewer " )
87+ if (versionViewer > 50u && failOnUnsupported)
88+ throw UnsupportedOperationException (" ZIP version not supported : $versionViewer " )
8889 it.skip(8 ) // Disk info
8990 it.skip(8 ) // Number of CDRs on disk
9091 cdrCount = it.readLongLe()
@@ -122,7 +123,8 @@ class ZipReader(context: Context, archiveUri: Uri) {
122123 }
123124 it.skip(4 ) // Version (creator and viewer)
124125 val flags = it.readUShortLe()
125- if (1u == flags % 2u ) throw UnsupportedOperationException (" Encrypted ZIP entries are not supported" )
126+ if (1u == flags % 2u && failOnUnsupported)
127+ throw UnsupportedOperationException (" Encrypted ZIP entries are not supported" )
126128 val compressionMode = it.readUShortLe()
127129 if (compressionMode > 0u ) hasOneCompressed = true
128130 val datetime = dosToJavaTime(it.readUIntLe().toLong())
@@ -172,7 +174,8 @@ class ZipReader(context: Context, archiveUri: Uri) {
172174 do {
173175 it.skip(2 ) // Version (viewer)
174176 val flags = it.readUShortLe()
175- if (1u == flags % 2u ) throw UnsupportedOperationException (" Encrypted ZIP entries are not supported" )
177+ if (1u == flags % 2u && failOnUnsupported)
178+ throw UnsupportedOperationException (" Encrypted ZIP entries are not supported" )
176179 val compressionMode = it.readUShortLe()
177180 if (compressionMode > 0u ) hasOneCompressed = true
178181 val datetime = dosToJavaTime(it.readUIntLe().toLong())
@@ -256,7 +259,7 @@ class ZipStream(context: Context, archiveUri: Uri, append: Boolean) : Closeable
256259 val sink: Sink
257260
258261 init {
259- records.addAll(ZipReader (context, archiveUri).records)
262+ records.addAll(ZipReader (context, archiveUri, true ).records)
260263
261264 val fileSize = fileSizeFromUri(context, archiveUri)
262265 val outStream = getOutputStream(context, archiveUri, append)
0 commit comments