class_docstr: An output target you can connect action signals to to implement
  behaviour.
class_docstr_tok: ["An","output","target","you","can","connect","action","signals","to","to","implement","behaviour","."]
docstr: Attach a write handler.
  
  The interface is exactly as io.write(). The handler is given a
  bytes-like object to write, and should return the number of bytes
  written.
docstr_tok: ["Attach","a","write","handler",".","The","interface","is","exactly","as","io.write","(",")",".","The","handler","is","given","a","bytes-like","object","to","write",",","and","should","return","the","number","of","bytes","written","."]
code: def on_write(self, handler):
      """Attach a write handler.
  
      The interface is exactly as io.write(). The handler is given a
      bytes-like object to write, and should return the number of bytes
      written.
  
      """
  
      def interface_handler(buf):
          bytes_written = handler(buf)
          # py2 will often return None for bytes_written ... replace with
          # the length of the string
          if bytes_written is None:
              bytes_written = len(buf)
  
          return bytes_written
  
      self.signal_connect("write", interface_handler)
  
file_path: pyvips/pyvips/vtargetcustom.py
imports: from __future__ import division
  import logging
  import pyvips
  from pyvips import ffi, vips_lib, at_least_libvips
label_desc: Use image node_id 2 for calling the TargetCustom obj's underlying member method code with example usage: obj.on_write(handler) and returns: bytes_written