private InputStream dataInputStream(long offset, long size) throws IOException {
        InputStream is;

        // use LZMA stream if the bundle is compressed
        if (bundle.header().compressed()) {
            // create initial input stream if required
            if (lzma == null) {
                lzma = lzmaInputStream();
            }

            // recreate stream if the offset is behind
            long lzmaOffset = lzma.getByteCount();
            if (lzmaOffset > offset) {
                lzma.close();
                lzma = lzmaInputStream();
            }

            // skip forward if required
            if (lzmaOffset < offset) {
                lzma.skip(offset - lzmaOffset);
            }

            is = lzma;
        } else {
            in.position(bundle.header().headerSize() + offset);
            is = in.stream();
        }

        return new BoundedInputStream(is, size);
    }
Streaming reader for Unity asset bundles.

@author Nico Bergemann <barracuda415 at yahoo.de>
disunity-core/src/main/java/info/ata4/junity/bundle/BundleReader.java