         // Check footer's magic number
         guard pointerData.intFromAlignedBytes(count: 2) == 0x5A59
             else { throw XZError.WrongMagic }
-
-        // STREAM PADDING
-        var rewind = 0
+    }
+
+}
+
+fileprivate extension DataWithPointer {
+
+    func multiByteDecode() throws -> (multiByteInteger: Int, bytesProcessed: [UInt8]) {
+        var result = self.alignedByte().toInt() & 0x7F
+        var bytes: [UInt8] = []
+        var i = 0
         while true {
-            let byte = pointerData.alignedByte()
-            if byte != 0 {
-                if rewind % 4 != 0 {
-                    throw XZError.WrongStreamPadding
-                } else {
-                    break
-                }
-            }
-            rewind += 1
-        }
-        pointerData.index -= rewind
-
-        return try LZMA.decompress(&pointerData)
-    }
-    
+            let byte = self.alignedByte()
+            if byte & 0x80 != 0 {
+                self.index -= 1
+                break
+            }
+            bytes.append(byte)
+            if i >= 9 || byte == 0x00 {
+                throw XZError.MultiByteIntegerError
+            }
+            result |= byte.toInt() & 0x7F << (i * 7)
+            i += 1
+        }
+        return (result, bytes)
+    }
+
 }
 
 
-

    case WrongFooterCRC
    /// Size of stream padding was not multiple of four.
    case WrongStreamPadding
}

/// A class with unarchive function for xz archives.
public class XZArchive: Archive {

    struct ServiceInfo {

    }

    /**

 - `WrongFooterFlagsLastFourBits`: last four bits of the flags in the footer weren't zero.
 - `WrongFooterCRC`: calculated crc-32 for footer's fields doesn't equal to the value stored in the archive.
 - `WrongStreamPadding`: the size of stream padding wasn't multiple of four.
 - `WrongBlockHeaderSize`: unsuported size of block's header (not in 0x01-0xFF range).
 - `WrongBlockFlags`: unsupported block flags.
 */
public enum XZError: Error {
    /// First six bytes of archive were not equal to 0xFD377A585A00.
