public InputStream toBytes() throws IOException {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        DataOutputStream outputStream = new DataOutputStream(buffer);
        outputStream.write(HEADER);

        checkIsShort(mRootObjects.size());
        outputStream.writeShort(mRootObjects.size());
        for (Archive.RootObject obj : mRootObjects) {
            outputStream.write(obj.mDigest.getBytes());
            outputStream.writeInt(obj.mKind);
        }

        checkIsShort(mBlockDescriptions.size());
        outputStream.writeShort(mBlockDescriptions.size());
        for (BlockDescription desc : mBlockDescriptions) {
            outputStream.writeLong(desc.mLength);
            checkIsShort(desc.mCHKs.size());
            outputStream.writeShort(desc.mCHKs.size());
            for (byte[] bytes : desc.mCHKs) {
                if (bytes.length != BINARY_CHK_LENGTH) {
                    throw new IllegalArgumentException("Not a binary CHK???");
                }
                outputStream.write(bytes);
            }
        }
        outputStream.close();
        byte[] bytes = buffer.toByteArray();
        if (bytes.length > MAX_LENGTH) {
            throw new IOException("Too big");
        }
        return new ByteArrayInputStream(bytes);
    }