sapling/tests/test-zstdelta.py
Jun Wu f4fdd7deea zstd: use Rust-backed bindings for its support
Summary:
This allows us to remove the Python binding without breaking existing zstd
users (commitcloud bundles). It might also make the future Rust migration
easier.

Using `zstd` create for its streaming APIs. `zstdelta`'s APIs cannot be used
since it requires decompressed length to be known, which wouldn't work for
streaming compressed data.

Note: For easier implementation, the Python land no longer processes data
in a streaming way. This is probably fine for the current bundle use-case.
In the long term, we might want to revisit the bundle format entirely.

As we're here, also expose zstdelta's APIs and add a test for it.

Reviewed By: DurhamG

Differential Revision: D8342421

fbshipit-source-id: 89902d551f4616469d6e1bc9b334a1c37c884775
2018-06-12 13:22:23 -07:00

25 lines
551 B
Python

from __future__ import absolute_import
import os
import unittest
import silenttestrunner
from mercurial.rust import zstd
class testzstd(unittest.TestCase):
def testdelta(self):
base = os.urandom(100000)
data = base[:1000] + "x" + base[1000:90000] + base[90500:]
delta = zstd.diff(base, data)
# The delta is tiny
self.assertLess(len(delta), 100)
# The delta can be applied
self.assertEqual(zstd.apply(base, delta), data)
if __name__ == "__main__":
silenttestrunner.main(__name__)