class_docstr: A file object providing transparent bzip2 (de)compression.
  
  A BZ2File can act as a wrapper for an existing file object, or refer
  directly to a named file on disk.
  
  Note that BZ2File provides a *binary* file interface - data read is
  returned as bytes, and data to be written should be given as bytes.
class_docstr_tok: ["A","file","object","providing","transparent","bzip2","(","de",")","compression",".","A","BZ2File","can","act","as","a","wrapper","for","an","existing","file","object",",","or","refer","directly","to","a","named","file","on","disk",".","Note","that","BZ2File","provides","a","*","binary","*","file","interface","-","data","read","is","returned","as","bytes",",","and","data","to","be","written","should","be","given","as","bytes","."]
docstr: Write a byte string to the file.
  
  Returns the number of uncompressed bytes written, which is
  always the length of data in bytes. Note that due to buffering,
  the file on disk may not reflect the data written until close()
  is called.
docstr_tok: ["Write","a","byte","string","to","the","file",".","Returns","the","number","of","uncompressed","bytes","written",",","which","is","always","the","length","of","data","in","bytes",".","Note","that","due","to","buffering",",","the","file","on","disk","may","not","reflect","the","data","written","until","close","(",")","is","called","."]
code: def write(self, data):
      """Write a byte string to the file.
  
      Returns the number of uncompressed bytes written, which is
      always the length of data in bytes. Note that due to buffering,
      the file on disk may not reflect the data written until close()
      is called.
      """
      self._check_can_write()
      if isinstance(data, (bytes, bytearray)):
          length = len(data)
      else:
          # accept any data that supports the buffer protocol
          data = memoryview(data)
          length = data.nbytes
  
      compressed = self._compressor.compress(data)
      self._fp.write(compressed)
      self._pos += length
      return length
  
imports: from builtins import open
  import io
  import os
  import _compression
  from _bz2 import BZ2Compressor, BZ2Decompressor
label_desc: Use image node_id 14 for calling the BZ2File obj's underlying member method code with example usage: obj.write(data) and returns: length