11Option Strict On
22Option Explicit On
33
4+ Imports System.IO
5+
46Namespace Global .Tomtastisch.FileClassifier
57 Friend Enum ArchiveContainerType
68 Unknown = 0
@@ -46,14 +48,14 @@ Namespace Global.Tomtastisch.FileClassifier
4648 ReadOnly Property UncompressedSize As Long ?
4749 ReadOnly Property CompressedSize As Long ?
4850 ReadOnly Property LinkTarget As String
49- Function OpenStream() As System.IO. Stream
51+ Function OpenStream() As Stream
5052 End Interface
5153
5254 Friend Interface IArchiveBackend
5355 ReadOnly Property ContainerType As ArchiveContainerType
5456
5557 Function Process(
56- stream As System.IO. Stream,
58+ stream As Stream,
5759 opt As FileTypeProjectOptions,
5860 depth As Integer ,
5961 containerTypeValue As ArchiveContainerType,
@@ -91,7 +93,7 @@ Namespace Global.Tomtastisch.FileClassifier
9193 If data Is Nothing OrElse data.Length = 0 Then Return False
9294
9395 Try
94- Using ms As New System.IO. MemoryStream(data, writable:= False )
96+ Using ms As New MemoryStream(data, writable:= False )
9597 Return TryDescribeStream(ms, opt, descriptor)
9698 End Using
9799 Catch ex As Exception
@@ -101,7 +103,7 @@ Namespace Global.Tomtastisch.FileClassifier
101103 End Try
102104 End Function
103105
104- Friend Shared Function TryDescribeStream(stream As System.IO. Stream, opt As FileTypeProjectOptions,
106+ Friend Shared Function TryDescribeStream(stream As Stream, opt As FileTypeProjectOptions,
105107 ByRef descriptor As ArchiveDescriptor) As Boolean
106108 descriptor = ArchiveDescriptor.UnknownDescriptor()
107109 If Not StreamGuard.IsReadable(stream) Then Return False
@@ -151,13 +153,13 @@ Namespace Global.Tomtastisch.FileClassifier
151153 Private Sub New ()
152154 End Sub
153155
154- Friend Shared Function ValidateArchiveStream(stream As System.IO. Stream, opt As FileTypeProjectOptions, depth As Integer ,
156+ Friend Shared Function ValidateArchiveStream(stream As Stream, opt As FileTypeProjectOptions, depth As Integer ,
155157 descriptor As ArchiveDescriptor) As Boolean
156158 Return ProcessArchiveStream(stream, opt, depth, descriptor, Nothing )
157159 End Function
158160
159161 Friend Shared Function ProcessArchiveStream(
160- stream As System.IO. Stream,
162+ stream As Stream,
161163 opt As FileTypeProjectOptions,
162164 depth As Integer ,
163165 descriptor As ArchiveDescriptor,
@@ -179,15 +181,15 @@ Namespace Global.Tomtastisch.FileClassifier
179181 Private Sub New ()
180182 End Sub
181183
182- Friend Shared Function TryExtractArchiveStreamToMemory(stream As System.IO. Stream, opt As FileTypeProjectOptions) _
184+ Friend Shared Function TryExtractArchiveStreamToMemory(stream As Stream, opt As FileTypeProjectOptions) _
183185 As IReadOnlyList( Of ZipExtractedEntry)
184186 Dim descriptor As ArchiveDescriptor = Nothing
185187 Dim emptyResult As IReadOnlyList( Of ZipExtractedEntry) = Array.Empty( Of ZipExtractedEntry)()
186188 If Not ArchiveTypeResolver.TryDescribeStream(stream, opt, descriptor) Then Return emptyResult
187189 Return TryExtractArchiveStreamToMemory(stream, opt, descriptor)
188190 End Function
189191
190- Friend Shared Function TryExtractArchiveStreamToMemory(stream As System.IO. Stream, opt As FileTypeProjectOptions,
192+ Friend Shared Function TryExtractArchiveStreamToMemory(stream As Stream, opt As FileTypeProjectOptions,
191193 descriptor As ArchiveDescriptor) _
192194 As IReadOnlyList( Of ZipExtractedEntry)
193195 Dim emptyResult As IReadOnlyList( Of ZipExtractedEntry) = Array.Empty( Of ZipExtractedEntry)()
@@ -220,14 +222,14 @@ Namespace Global.Tomtastisch.FileClassifier
220222 End Try
221223 End Function
222224
223- Friend Shared Function TryExtractArchiveStream(stream As System.IO. Stream, destinationDirectory As String ,
225+ Friend Shared Function TryExtractArchiveStream(stream As Stream, destinationDirectory As String ,
224226 opt As FileTypeProjectOptions) As Boolean
225227 Dim descriptor As ArchiveDescriptor = Nothing
226228 If Not ArchiveTypeResolver.TryDescribeStream(stream, opt, descriptor) Then Return False
227229 Return TryExtractArchiveStream(stream, destinationDirectory, opt, descriptor)
228230 End Function
229231
230- Friend Shared Function TryExtractArchiveStream(stream As System.IO. Stream, destinationDirectory As String ,
232+ Friend Shared Function TryExtractArchiveStream(stream As Stream, destinationDirectory As String ,
231233 opt As FileTypeProjectOptions, descriptor As ArchiveDescriptor) _
232234 As Boolean
233235 If Not StreamGuard.IsReadable(stream) Then Return False
@@ -237,25 +239,25 @@ Namespace Global.Tomtastisch.FileClassifier
237239
238240 Dim destinationFull As String
239241 Try
240- destinationFull = System.IO. Path.GetFullPath(destinationDirectory)
242+ destinationFull = Path.GetFullPath(destinationDirectory)
241243 Catch ex As Exception
242244 LogGuard.Debug(opt.Logger, $"[ArchiveExtract] Ungueltiger Zielpfad: {ex.Message}" )
243245 Return False
244246 End Try
245247
246248 If Not DestinationPathGuard.ValidateNewExtractionTarget(destinationFull, opt) Then Return False
247249
248- Dim parent = System.IO. Path.GetDirectoryName(destinationFull)
250+ Dim parent = Path.GetDirectoryName(destinationFull)
249251 If String .IsNullOrWhiteSpace(parent) Then Return False
250252
251253 Dim stageDir = destinationFull & ".stage-" & Guid.NewGuid().ToString( "N" )
252254 Try
253- System.IO. Directory.CreateDirectory(parent)
254- System.IO. Directory.CreateDirectory(stageDir)
255+ Directory.CreateDirectory(parent)
256+ Directory.CreateDirectory(stageDir)
255257
256258 StreamGuard.RewindToStart(stream)
257259
258- Dim stagePrefix = EnsureTrailingSeparator(System.IO. Path.GetFullPath(stageDir))
260+ Dim stagePrefix = EnsureTrailingSeparator(Path.GetFullPath(stageDir))
259261 Dim ok = ArchiveProcessingEngine.ProcessArchiveStream(
260262 stream,
261263 opt,
@@ -266,15 +268,15 @@ Namespace Global.Tomtastisch.FileClassifier
266268 End Function )
267269 If Not ok Then Return False
268270
269- System.IO. Directory.Move(stageDir, destinationFull)
271+ Directory.Move(stageDir, destinationFull)
270272 Return True
271273 Catch ex As Exception
272274 LogGuard.Debug(opt.Logger, $"[ArchiveExtract] Fehler: {ex.Message}" )
273275 Return False
274276 Finally
275- If System.IO. Directory.Exists(stageDir) Then
277+ If Directory.Exists(stageDir) Then
276278 Try
277- System.IO. Directory.Delete(stageDir, recursive:= True )
279+ Directory.Delete(stageDir, recursive:= True )
278280 Catch
279281 End Try
280282 End If
@@ -292,7 +294,7 @@ Namespace Global.Tomtastisch.FileClassifier
292294
293295 Dim targetPath As String
294296 Try
295- targetPath = System.IO. Path.GetFullPath(System.IO. Path.Combine(destinationPrefix, entryName))
297+ targetPath = Path.GetFullPath(Path.Combine(destinationPrefix, entryName))
296298 Catch
297299 Return False
298300 End Try
@@ -303,17 +305,17 @@ Namespace Global.Tomtastisch.FileClassifier
303305 End If
304306
305307 If isDirectory Then
306- System.IO. Directory.CreateDirectory(targetPath)
308+ Directory.CreateDirectory(targetPath)
307309 Return True
308310 End If
309311
310312 If Not ValidateEntrySize(entry, opt) Then Return False
311313
312- Dim targetDir = System.IO. Path.GetDirectoryName(targetPath)
314+ Dim targetDir = Path.GetDirectoryName(targetPath)
313315 If String .IsNullOrWhiteSpace(targetDir) Then Return False
314- System.IO. Directory.CreateDirectory(targetDir)
316+ Directory.CreateDirectory(targetDir)
315317
316- If System.IO. File.Exists(targetPath) OrElse System.IO. Directory.Exists(targetPath) Then
318+ If File.Exists(targetPath) OrElse Directory.Exists(targetPath) Then
317319 LogGuard.Warn(opt.Logger, "[ArchiveExtract] Kollision bei Zielpfad." )
318320 Return False
319321 End If
@@ -323,8 +325,8 @@ Namespace Global.Tomtastisch.FileClassifier
323325 If source Is Nothing OrElse Not source.CanRead Then Return False
324326 Using _
325327 target As _
326- New System.IO. FileStream(targetPath, System.IO. FileMode.CreateNew, System.IO. FileAccess.Write, System.IO. FileShare.None,
327- InternalIoDefaults.FileStreamBufferSize, System.IO. FileOptions.SequentialScan)
328+ New FileStream(targetPath, FileMode.CreateNew, FileAccess.Write, FileShare.None,
329+ InternalIoDefaults.FileStreamBufferSize, FileOptions.SequentialScan)
328330 StreamBounds.CopyBounded(source, target, opt.MaxZipEntryUncompressedBytes)
329331 End Using
330332 End Using
@@ -413,12 +415,12 @@ Namespace Global.Tomtastisch.FileClassifier
413415 End Function
414416
415417 Private Shared Function EnsureTrailingSeparator(dirPath As String ) As String
416- If String .IsNullOrEmpty(dirPath) Then Return System.IO. Path.DirectorySeparatorChar.ToString()
417- If dirPath.EndsWith(System.IO. Path.DirectorySeparatorChar) OrElse dirPath.EndsWith(System.IO. Path.AltDirectorySeparatorChar) _
418+ If String .IsNullOrEmpty(dirPath) Then Return Path.DirectorySeparatorChar.ToString()
419+ If dirPath.EndsWith(Path.DirectorySeparatorChar) OrElse dirPath.EndsWith(Path.AltDirectorySeparatorChar) _
418420 Then
419421 Return dirPath
420422 End If
421- Return dirPath & System.IO. Path.DirectorySeparatorChar
423+ Return dirPath & Path.DirectorySeparatorChar
422424 End Function
423425 End Class
424426
@@ -429,14 +431,14 @@ Namespace Global.Tomtastisch.FileClassifier
429431 Friend Shared Function TryCollectFromFile(path As String , opt As FileTypeProjectOptions,
430432 ByRef entries As IReadOnlyList( Of ZipExtractedEntry)) As Boolean
431433 entries = Array.Empty( Of ZipExtractedEntry)()
432- If String .IsNullOrWhiteSpace(path) OrElse Not System.IO. File.Exists(path) Then Return False
434+ If String .IsNullOrWhiteSpace(path) OrElse Not File.Exists(path) Then Return False
433435 If opt Is Nothing Then Return False
434436
435437 Try
436438 Using _
437439 fs As _
438- New System.IO. FileStream(path, System.IO. FileMode.Open, System.IO. FileAccess.Read, System.IO. FileShare.Read,
439- InternalIoDefaults.FileStreamBufferSize, System.IO. FileOptions.SequentialScan)
440+ New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read,
441+ InternalIoDefaults.FileStreamBufferSize, FileOptions.SequentialScan)
440442 Dim descriptor As ArchiveDescriptor = Nothing
441443 If Not ArchiveTypeResolver.TryDescribeStream(fs, opt, descriptor) Then Return False
442444 StreamGuard.RewindToStart(fs)
@@ -461,7 +463,7 @@ Namespace Global.Tomtastisch.FileClassifier
461463 Dim descriptor As ArchiveDescriptor = Nothing
462464 If Not ArchiveTypeResolver.TryDescribeBytes(data, opt, descriptor) Then Return False
463465 If Not ArchiveSafetyGate.IsArchiveSafeBytes(data, opt, descriptor) Then Return False
464- Using ms As New System.IO. MemoryStream(data, writable:= False )
466+ Using ms As New MemoryStream(data, writable:= False )
465467 entries = ArchiveExtractor.TryExtractArchiveStreamToMemory(ms, opt, descriptor)
466468 Return entries IsNot Nothing AndAlso entries.Count > 0
467469 End Using
@@ -482,7 +484,7 @@ Namespace Global.Tomtastisch.FileClassifier
482484 End Property
483485
484486 Public Function Process(
485- stream As System.IO. Stream,
487+ stream As Stream,
486488 opt As FileTypeProjectOptions,
487489 depth As Integer ,
488490 containerTypeValue As ArchiveContainerType,
@@ -584,7 +586,7 @@ Namespace Global.Tomtastisch.FileClassifier
584586 Return True
585587 End If
586588
587- Using nestedMs As New System.IO. MemoryStream(payload, writable:= False )
589+ Using nestedMs As New MemoryStream(payload, writable:= False )
588590 nestedResult = ArchiveProcessingEngine.ProcessArchiveStream(nestedMs, opt, depth + 1 , nestedDescriptor,
589591 extractEntry)
590592 End Using
@@ -600,7 +602,7 @@ Namespace Global.Tomtastisch.FileClassifier
600602 Try
601603 Using source = entry.OpenEntryStream()
602604 If source Is Nothing OrElse Not source.CanRead Then Return False
603- Using ms As New System.IO. MemoryStream()
605+ Using ms As New MemoryStream()
604606 StreamBounds.CopyBounded(source, ms, maxBytes)
605607 payload = ms.ToArray()
606608 Return True
@@ -706,8 +708,8 @@ Namespace Global.Tomtastisch.FileClassifier
706708 End Get
707709 End Property
708710
709- Public Function OpenStream() As System.IO. Stream Implements IArchiveEntryModel.OpenStream
710- If _entry Is Nothing Then Return System.IO. Stream.Null
711+ Public Function OpenStream() As Stream Implements IArchiveEntryModel.OpenStream
712+ If _entry Is Nothing Then Return Stream.Null
711713 Return _entry.OpenEntryStream()
712714 End Function
713715 End Class
0 commit comments