File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
Sources/Streamer/Parser/EPUB/Resource Transformers Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -72,21 +72,25 @@ final class EPUBDeobfuscator {
7272 }
7373
7474 func stream( range: Range < UInt64 > ? , consume: @escaping ( Data ) -> Void ) async -> ReadResult < Void > {
75- await resource. stream (
75+ var readPosition = range? . lowerBound ?? 0
76+ let obfuscatedLength = algorithm. obfuscatedLength
77+
78+ return await resource. stream (
7679 range: range,
7780 consume: { data in
7881 var data = data
7982
80- let range = range ?? 0 ..< UInt64 ( data. count)
81- if range. lowerBound < self . algorithm. obfuscatedLength {
82- let toDeobfuscate = max ( range. lowerBound, 0 ) ..< min ( range. upperBound, UInt64 ( self . algorithm. obfuscatedLength) )
83-
84- for i in toDeobfuscate {
85- let i = Int ( i)
83+ if readPosition < obfuscatedLength {
84+ for i in 0 ..< data. count {
85+ if readPosition + UInt64( i) >= obfuscatedLength {
86+ break
87+ }
8688 data [ i] = data [ i] ^ self . key [ i % self . key. count]
8789 }
8890 }
8991
92+ readPosition += UInt64 ( data. count)
93+
9094 consume ( data)
9195 }
9296 )
You can’t perform that action at this time.
0 commit comments