code: def create(filename, spec):
      from . import _segyio
      if not structured(spec):
          tracecount = spec.tracecount
      else:
          tracecount = len(spec.ilines) * len(spec.xlines) * len(spec.offsets)
      ext_headers = spec.ext_headers if hasattr(spec, 'ext_headers') else 0
      samples = numpy.asarray(spec.samples)
      endians = {
          'lsb': 256,
          'little': 256,
          'msb': 0,
          'big': 0,
      }
      endian = spec.endian if hasattr(spec, 'endian') else 'big'
      if endian is None:
          endian = 'big'
      if endian not in endians:
          problem = 'unknown endianness {}, expected one of: '
          opts = ' '.join(endians.keys())
          raise ValueError(problem.format(endian) + opts)
      fd = _segyio.segyiofd(str(filename), 'w+', endians[endian])
      fd.segymake(
          samples = len(samples),
          tracecount = tracecount,
          format = int(spec.format),
          ext_headers = int(ext_headers),
      )
      f = segyio.SegyFile(fd,
              filename = str(filename),
              mode = 'w+',
              iline = int(spec.iline),
              xline = int(spec.xline),
              endian = endian,
      )
      f._samples       = samples
      if structured(spec):
          sorting = spec.sorting if hasattr(spec, 'sorting') else None
          if sorting is None:
              sorting = TraceSortingFormat.INLINE_SORTING
          f.interpret(spec.ilines, spec.xlines, spec.offsets, sorting)
      f.text[0] = default_text_header(f._il, f._xl, segyio.TraceField.offset)
      if len(samples) == 1:
          interval = int(samples[0] * 1000)
      else:
          interval = int((samples[1] - samples[0]) * 1000)
      f.bin.update(
          ntrpr    = tracecount,
          nart     = tracecount,
          hdt      = interval,
          dto      = interval,
          hns      = len(samples),
          nso      = len(samples),
          format   = int(spec.format),
          exth     = ext_headers,
      )
      return f