 
             out.append(try LZ4.process(block: blockData))
         }
-        return out
-    }
-
-    private static func process(frame data: Data, _ dictionary: Data?, _ extDictId: UInt32?) throws -> Data {
+        return (out, reader.offset)
+    }
+
+    private static func process(frame data: Data, _ dictionary: Data?, _ extDictId: UInt32?) throws -> (Data, Data.Index) {
         // Valid LZ4 frame must contain frame descriptor (at least 3 bytes) and EndMark (4 bytes), assuming no data blocks.
         guard data.count >= 7
             else { throw DataError.truncated }


public enum LZ4: DecompressionAlgorithm {

    public static func decompress(data: Data) throws -> Data {
        return try LZ4.decompress(data: data, dictionary: nil)
    }

        // Valid LZ4 frame must contain at least a magic number (4 bytes).
        guard data.count >= 4
            else { throw DataError.truncated }

        // Magic number.
        let magic = data[data.startIndex..<data.startIndex + 4].withUnsafeBytes { $0.bindMemory(to: UInt32.self)[0] }
        switch magic {
        case 0x184D2204:
            return try LZ4.process(frame: data[(data.startIndex + 4)...], dictionary, dictionaryID).0
        case 0x184D2A50...0x184D2A5F:
            let frameSize = try process(skippableFrame: data[(data.startIndex + 4)...])
            return try LZ4.decompress(data: data[(data.startIndex + 4 + frameSize)...])
        case 0x184C2102:
            return try LZ4.process(legacyFrame: data[(data.startIndex + 4)...]).0
        default:
            throw DataError.corrupted
        }
    }

    public static func multiDecompress(data: Data, dictionary: Data? = nil, dictionaryID: UInt32? = nil) throws -> [Data] {
        var result = [Data]()
        var nextFrameOffset = data.startIndex

        repeat {
            // Magic number.
            // The input must contain at least one valid LZ4 frame, which in turn must contain at least a magic number.
            guard nextFrameOffset + 4 <= data.endIndex
                else { throw DataError.truncated }
            let magic = data[nextFrameOffset..<nextFrameOffset + 4].withUnsafeBytes { $0.bindMemory(to: UInt32.self)[0] }
            nextFrameOffset += 4
            var out: Data? = nil

            switch magic {
            case 0x184D2204:
                (out, nextFrameOffset) = try LZ4.process(frame: data[nextFrameOffset...], dictionary, dictionaryID)
            case 0x184D2A50...0x184D2A5F:
                nextFrameOffset += try process(skippableFrame: data[nextFrameOffset...])
            case 0x184C2102:
                (out, nextFrameOffset) = try LZ4.process(legacyFrame: data[nextFrameOffset...])
            default:
                throw DataError.corrupted
            }

            if let out = out {
                result.append(out)
            }
        } while nextFrameOffset < data.endIndex

        return result
    }

    private static func process(skippableFrame data: Data) throws -> Data.Index {
