class_docstr: A file object providing transparent zlib (de)compression.
  
  TODO python2_drop: is it still needed since we dropped Python 2 support A
  BinaryZlibFile can act as a wrapper for an existing file object, or refer
  directly to a named file on disk.
  
  Note that BinaryZlibFile provides only a *binary* file interface: data read
  is returned as bytes, and data to be written should be given as bytes.
  
  This object is an adaptation of the BZ2File object and is compatible with
  versions of python >= 2.7.
  
  If filename is a str or bytes object, it gives the name
  of the file to be opened. Otherwise, it should be a file object,
  which will be used to read or write the compressed data.
  
  mode can be 'rb' for reading (default) or 'wb' for (over)writing
  
  If mode is 'wb', compresslevel can be a number between 1
  and 9 specifying the level of compression: 1 produces the least
  compression, and 9 produces the most compression. 3 is the default.
class_docstr_tok: ["A","file","object","providing","transparent","zlib","(","de",")","compression",".","TODO","python2_drop",":","is","it","still","needed","since","we","dropped","Python","2","support","A","BinaryZlibFile","can","act","as","a","wrapper","for","an","existing","file","object",",","or","refer","directly","to","a","named","file","on","disk",".","Note","that","BinaryZlibFile","provides","only","a","*","binary","*","file","interface",":","data","read","is","returned","as","bytes",",","and","data","to","be","written","should","be","given","as","bytes",".","This","object","is","an","adaptation","of","the","BZ2File","object","and","is","compatible","with","versions","of","python",">","=","2.7",".","If","filename","is","a","str","or","bytes","object",",","it","gives","the","name","of","the","file","to","be","opened",".","Otherwise",",","it","should","be","a","file","object",",","which","will","be","used","to","read","or","write","the","compressed","data",".","mode","can","be","'rb","'","for","reading","(","default",")","or","'wb","'","for","(","over",")","writing","If","mode","is","'wb","'",",","compresslevel","can","be","a","number","between","1","and","9","specifying","the","level","of","compression",":","1","produces","the","least","compression",",","and","9","produces","the","most","compression",".","3","is","the","default","."]
code: def __init__(self, filename, mode="rb", compresslevel=3):
      # This lock must be recursive, so that BufferedIOBase's
      # readline(), readlines() and writelines() don't deadlock.
      self._lock = RLock()
      self._fp = None
      self._closefp = False
      self._mode = _MODE_CLOSED
      self._pos = 0
      self._size = -1
      self.compresslevel = compresslevel
  
      if not isinstance(compresslevel, int) or not (
          1 <= compresslevel <= 9
      ):
          raise ValueError(
              "'compresslevel' must be an integer "
              "between 1 and 9. You provided 'compresslevel={}'".format(
                  compresslevel
              )
          )
  
      if mode == "rb":
          self._mode = _MODE_READ
          self._decompressor = zlib.decompressobj(self.wbits)
          self._buffer = b""
          self._buffer_offset = 0
      elif mode == "wb":
          self._mode = _MODE_WRITE
          self._compressor = zlib.compressobj(
              self.compresslevel,
              zlib.DEFLATED,
              self.wbits,
              zlib.DEF_MEM_LEVEL,
              0,
          )
      else:
          raise ValueError("Invalid mode: %r" % (mode,))
  
      if isinstance(filename, str):
          self._fp = io.open(filename, mode)
          self._closefp = True
      elif hasattr(filename, "read") or hasattr(filename, "write"):
          self._fp = filename
      else:
          raise TypeError(
              "filename must be a str or bytes object, " "or a file"
          )
  
imports: import io
  import zlib
  from joblib.backports import LooseVersion
label_desc: Use image node_id 1 to create a new BinaryZlibFile object from inherited base classes: io with example: obj = BinaryZlibFile(filename, mode, compresslevel)