code: def fromfile(
      fd,
      dtype=None,
      shape=None,
      offset=0,
      formats=None,
      names=None,
      titles=None,
      aligned=False,
      byteorder=None,
  ):
      """Create an array from binary file data
  
      If file is a string or a path-like object then that file is opened,
      else it is assumed to be a file object. The file object must
      support random access (i.e. it must have tell and seek methods).
  
      >>> from tempfile import TemporaryFile
      >>> a = np.empty(10,dtype='f8,i4,a5')
      >>> a[5] = (0.5,10,'abcde')
      >>>
      >>> fd=TemporaryFile()
      >>> a = a.newbyteorder('<')
      >>> a.tofile(fd)
      >>>
      >>> fd.seek(0)
      >>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,
      ... byteorder='<')
      >>> print(r[5])
      (0.5, 10, 'abcde')
      >>> r.shape
      (10,)
      """
  
      if dtype is None and formats is None:
          raise TypeError(
              "fromfile() needs a 'dtype' or 'formats' argument"
          )
  
      if shape is None or shape == 0:
          shape = (-1,)
      elif isinstance(shape, (int, long)):
          shape = (shape,)
  
      if isfileobj(fd):
          # file already opened
          name = 0
      else:
          # open file
          fd = open(os_fspath(fd), "rb")
          name = 1
  
      if offset > 0:
          fd.seek(offset, 1)
      size = get_remaining_size(fd)
  
      if dtype is not None:
          descr = sb.dtype(dtype)
      else:
          descr = format_parser(
              formats, names, titles, aligned, byteorder
          )._descr
  
      itemsize = descr.itemsize
  
      shapeprod = sb.array(shape).prod(dtype=nt.intp)
      shapesize = shapeprod * itemsize
      if shapesize < 0:
          shape = list(shape)
          shape[shape.index(-1)] = size // -shapesize
          shape = tuple(shape)
          shapeprod = sb.array(shape).prod(dtype=nt.intp)
  
      nbytes = shapeprod * itemsize
  
      if nbytes > size:
          raise ValueError(
              "Not enough bytes left in file for specified shape and type"
          )
  
      # create the array
      _array = recarray(shape, descr)
      nbytesread = fd.readinto(_array.data)
      if nbytesread != nbytes:
          raise IOError("Didn't read as many bytes as expected")
      if name:
          fd.close()
  
      return _array
  
imports: from __future__ import division, absolute_import, print_function
  import sys
  import os
  import warnings
  from .None import numeric
  from .None import numerictypes
  from numpy.compat import isfileobj, bytes, long, unicode, os_fspath
  from numpy.core.overrides import set_module
  from .arrayprint import get_printoptions
label_desc: Use image node_id 6 for calling a global function with example usage: fromfile(fd, dtype, shape, offset, formats, names, titles, aligned, byteorder) and returns: _array