docs: def _write_wrapped_codestream(self, ofile, box):
          """Write wrapped codestream."""
          # Codestreams require a bit more care.
          # Am I a raw codestream?
          if len(self.box) == 0:
              # Yes, just write the codestream box header plus all
              # of myself out to file.
              ofile.write(struct.pack('>I', self.length + 8))
              ofile.write(b'jp2c')
              with open(self.filename, 'rb') as ifile:
                  ofile.write(ifile.read())
              return
  
          # OK, I'm a jp2/jpx file.  Need to find out where the raw codestream
          # actually starts.
          offset = box.offset
          if offset == -1:
              if self.box[1].brand == 'jpx ':
                  msg = ("The codestream box must have its offset and length "
                         "attributes fully specified if the file type brand is "
                         "JPX.")
                  raise IOError(msg)
  
              # Find the first codestream in the file.
              jp2c = [_box for _box in self.box if _box.box_id == 'jp2c']
              offset = jp2c[0].offset
  
          # Ready to write the codestream.
          with open(self.filename, 'rb') as ifile:
              ifile.seek(offset)
  
              # Verify that the specified codestream is right.
              read_buffer = ifile.read(8)
              L, T = struct.unpack_from('>I4s', read_buffer, 0)
              if T != b'jp2c':
                  msg = "Unable to locate the specified codestream."
                  raise IOError(msg)
              if L == 0:
                  # The length of the box is presumed to last until the end of
                  # the file.  Compute the effective length of the box.
                  L = os.path.getsize(ifile.name) - ifile.tell() + 8
  
              elif L == 1:
                  # The length of the box is in the XL field, a 64-bit value.
                  read_buffer = ifile.read(8)
                  L, = struct.unpack('>Q', read_buffer)
  
              ifile.seek(offset)
              read_buffer = ifile.read(L)
              ofile.write(read_buffer)