code: def target_custom(filename):
      # w+ means read and write ... we need to be able to read from our output
      # stream for TIFF write
      output_file = open(sys.argv[2], "w+b")
  
      def write_handler(chunk):
          return output_file.write(chunk)
  
      # read and seek are optional and only needed for formats like TIFF
      def read_handler(size):
          return output_file.read(size)
  
      def seek_handler(offset, whence):
          output_file.seek(offset, whence)
          return output_file.tell()
  
      def end_handler():
          # you can't throw exceptions over on_ handlers, you must return an
          # error code
          try:
              output_file.close()
          except IOError:
              return -1
          else:
              return 0
  
      target = pyvips.TargetCustom()
      target.on_write(write_handler)
      target.on_read(read_handler)
      target.on_seek(seek_handler)
      target.on_end(end_handler)
  
      return target
  
label_desc: Use image node_id 2 for calling a global function with example usage: target_custom(filename) and returns: target, output_file, output_file, output_file, int, unknown