code: def test_target_custom(self):
      filename = temp_filename(self.tempdir, ".png")
      output_file = open(filename, "w+b")
  
      def write_handler(chunk):
          return output_file.write(chunk)
  
      def end_handler():
          try:
              output_file.close()
          except IOError:
              return -1
          else:
              return 0
  
      target = pyvips.TargetCustom()
      target.on_write(write_handler)
      target.on_end(end_handler)
  
      image = pyvips.Image.new_from_file(JPEG_FILE, access="sequential")
      image.write_to_target(target, ".png")
  
      image = pyvips.Image.new_from_file(JPEG_FILE, access="sequential")
      image2 = pyvips.Image.new_from_file(filename, access="sequential")
  
      assert (image - image2).abs().max() == 0
  
file_path: pyvips/tests/test_connections.py
imports: import tempfile
  import pytest
  import pyvips
  from helpers import JPEG_FILE, WEBP_FILE, temp_filename, skip_if_no
label_desc: Use image node_id 5 for calling the TestConnections obj's underlying member method code with example usage: obj.test_target_custom() and returns: output_file, int, unknown