code: def _safe_read(fp, size):
      """
      Reads large blocks in a safe way.  Unlike fp.read(n), this function
      doesn't trust the user.  If the requested size is larger than
      SAFEBLOCK, the file is read block by block.
  
      :param fp: File handle.  Must implement a <b>read</b> method.
      :param size: Number of bytes to read.
      :returns: A string containing up to <i>size</i> bytes of data.
      """
      if size <= 0:
          return b""
      if size <= SAFEBLOCK:
          return fp.read(size)
      data = []
      while size > 0:
          block = fp.read(min(size, SAFEBLOCK))
          if not block:
              break
          data.append(block)
          size -= len(block)
      return b"".join(data)
  
imports: import io
  import struct
  import sys
  from .None import Image
  from ._util import isPath
label_desc: Use image node_id 4 for calling a global function with example usage: _safe_read(fp, size) and returns: bytes, bytes, fp