code: def read_segments(fileobj, segments, n_bytes, lock=None):
      """Read `n_bytes` byte data implied by `segments` from `fileobj`
  
      Parameters
      ----------
      fileobj : file-like object
          Implements `seek` and `read`
      segments : sequence
          list of 2 sequences where sequences are (offset, length), giving
          absolute file offset in bytes and number of bytes to read
      n_bytes : int
          total number of bytes that will be read
      lock : {None, threading.Lock, lock-like} optional
          If provided, used to ensure that paired calls to ``seek`` and ``read``
          cannot be interrupted by another thread accessing the same ``fileobj``.
          Each thread which accesses the same file via ``read_segments`` must
          share a lock in order to ensure that the file access is thread-safe.
          A lock does not need to be provided for single-threaded access. The
          default value (``None``) results in a lock-like object  (a
          ``_NullLock``) which does not do anything.
  
      Returns
      -------
      buffer : buffer object
          object implementing buffer protocol, such as byte string or ndarray or
          mmap or ctypes ``c_char_array``
      """
      # Make a lock-like thing to make the code below a bit nicer
      if lock is None:
          lock = _NullLock()
  
      if len(segments) == 0:
          if n_bytes != 0:
              raise ValueError("No segments, but non-zero n_bytes")
          return b""
      if len(segments) == 1:
          offset, length = segments[0]
          with lock:
              fileobj.seek(offset)
              bytes = fileobj.read(length)
          if len(bytes) != n_bytes:
              raise ValueError("Whoops, not enough data in file")
          return bytes
      # More than one segment
      bytes = mmap(-1, n_bytes)
      for offset, length in segments:
          with lock:
              fileobj.seek(offset)
              bytes.write(fileobj.read(length))
      if bytes.tell() != n_bytes:
          raise ValueError("Oh dear, n_bytes does not look right")
      return bytes
  
imports: import operator
  from functools import reduce
  from mmap import mmap
  from numbers import Integral
  import numpy
label_desc: Use image node_id 14 for calling a global function with example usage: read_segments(fileobj, segments, n_bytes, lock) and returns: bytes, bytes, bytes