mercurial/util.py
changeset 30442 41a8106789ca
parent 30438 90933e4e44fd
child 30471 00c9ac4ce816
equal deleted inserted replaced
30441:de48d3a0573a 30442:41a8106789ca
  3195     def decompressorreader(self, fh):
  3195     def decompressorreader(self, fh):
  3196         return fh
  3196         return fh
  3197 
  3197 
  3198 compengines.register(_noopengine())
  3198 compengines.register(_noopengine())
  3199 
  3199 
       
  3200 class _zstdengine(compressionengine):
       
  3201     def name(self):
       
  3202         return 'zstd'
       
  3203 
       
  3204     @propertycache
       
  3205     def _module(self):
       
  3206         # Not all installs have the zstd module available. So defer importing
       
  3207         # until first access.
       
  3208         try:
       
  3209             from . import zstd
       
  3210             # Force delayed import.
       
  3211             zstd.__version__
       
  3212             return zstd
       
  3213         except ImportError:
       
  3214             return None
       
  3215 
       
  3216     def available(self):
       
  3217         return bool(self._module)
       
  3218 
       
  3219     def bundletype(self):
       
  3220         return 'zstd', 'ZS'
       
  3221 
       
  3222     def compressstream(self, it, opts=None):
       
  3223         opts = opts or {}
       
  3224         # zstd level 3 is almost always significantly faster than zlib
       
  3225         # while providing no worse compression. It strikes a good balance
       
  3226         # between speed and compression.
       
  3227         level = opts.get('level', 3)
       
  3228 
       
  3229         zstd = self._module
       
  3230         z = zstd.ZstdCompressor(level=level).compressobj()
       
  3231         for chunk in it:
       
  3232             data = z.compress(chunk)
       
  3233             if data:
       
  3234                 yield data
       
  3235 
       
  3236         yield z.flush()
       
  3237 
       
  3238     def decompressorreader(self, fh):
       
  3239         zstd = self._module
       
  3240         dctx = zstd.ZstdDecompressor()
       
  3241         return chunkbuffer(dctx.read_from(fh))
       
  3242 
       
  3243 compengines.register(_zstdengine())
       
  3244 
  3200 # convenient shortcut
  3245 # convenient shortcut
  3201 dst = debugstacktrace
  3246 dst = debugstacktrace