anchor.diff:  
     static Uint8List write(Dataset ds,
         {String path = "",
  -      File file,
  -      bool fmiOnly = false,
  -      fast = false,
  -      TransferSyntax targetTS}) {
  +        File file,
  +        bool fmiOnly = false,
  +        fast = false,
  +        TransferSyntax targetTS}) {
       if (file != null)
         return writeFile(ds, file,
             fmiOnly: fmiOnly, fast: fast, targetTS: targetTS);
  
positive.code:   /// [Dataset] to it. Returns the [Uint8List].
    static Uint8List writeInstance(Instance instance,
        {String path = "",
        bool fmiOnly = false,
        fast = false,
        TransferSyntax targetTS}) {
      Dataset ds = instance.dataset;
      return (path == "")
          ? writeBytes(ds, fmiOnly: fmiOnly, fast: fast, targetTS: targetTS)
  
negative.code:     return v;
    }
  
  
    void _writeDataset(Dataset ds) {
      Dataset previousDS = _currentDS;
      _currentDS = ds;
      for (Element e in ds.elements) _writeElement(e);
      _currentDS = previousDS;
    }
  
    void _writeElement(Element e) {
      if (e.isSequence) {
       _writeSequence(e);
      } else if (e.hasUndefinedLength) {
        _writeUndefinedHeader(e);
        _writeBytes(e.vfBytes);
        _writeDelimiter(kSequenceDelimitationItem);
      } else {
        _writeHeader(e);
        _writeBytes(e.vfBytes);
      }
    }
  
    /// Writes an EVR (short == 8 bytes, long == 12 bytes) or IVR (8 bytes)
    /// header.
    void _writeHeader(Element e) {
      int start = _wIndex;
      // Write Tag
      _writeTagCode(e.code);
      if (isEVR) {
        // Write VR
        _writeUint16(e.vrCode);
        if (e.vr.hasShortVF) {
          // Write short EVR VF Length
          _writeUint16(e.vfBytes.lengthInBytes);
          assert(_wIndex == start + 8);
        } else {
          // Write long EVR VF Length
          _writeUint16(0);
          _writeUint32(e.vfBytes.lengthInBytes);
          assert(_wIndex == start + 12);
        }
      } else {
        // Write IVR VF Length
        _writeUint32(e.vfBytes.lengthInBytes);
        assert(_wIndex == start + 8);
      }
    }
  
    /// Writes an EVR (short == 8 bytes, long == 12 bytes) or IVR (8 bytes)
    /// header.
    void _writeUndefinedHeader(Element e) {
      int start = _wIndex;
      // Write Tag
      _writeTagCode(e.code);
      if (isEVR) {
        // Write VR
        _writeUint16(e.vrCode);
        _writeUint16(0);
        _writeUint32(e.vfBytes.lengthInBytes);
        assert(_wIndex == start + 12);
      } else {
        // Write IVR VF Length
        _writeUint32(e.vfBytes.lengthInBytes);
        assert(_wIndex == start + 8);
      }
    }
  
    void _writeTagCode(int code) {
      _writeUint16(code >> 16);
      _writeUint16(code & 0xFFFF);
    }
  
  
    void _writePrefix() {
      log.debug1('Writing Prefix');
      if (rootDS.hasFmi) {
        for (int i = 0; i < 128; i++) _writeUint8(rootDS.prefix[i]);
        _writeAsciiString('DICM');
      } else if (addMissingPrefix) {
        for (int i = 0; i < 128; i++) _writeUint8(0);
        _writeAsciiString('DICM');
      } else {
        log.error('Dataset $rootDS is missing DICOM Prefix');
      }
    }
  
  
    void _writeSequence(Element e) {
      _writeHeader(e);
      _writeItems(e.items);
      if (e.hasTrailer) _writeDelimiter(kSequenceDelimitationItem);
    }
  
    void _writeItems(List<Dataset> items) {
      for (Dataset item in items) {
        _writeDelimiter(kItem, e.vfLength);
        for (Element e in item) _writeElement(e);
        if (e.hadUndefinedLength) _writeDelimiter(kItemDelimitationItem);
      }
    }
  
    /// TODO: DOC
    _writeFragments(EVRPixelData e, bool isEVR) {
      _writeHeader(e);
      for (Uint8List f in e.fragments) {
        _writeTagCode(kItem);
        _writeUint32(f.lengthInBytes);
        _writeBytes(f);
      }
      _writeSequenceDelimiter();
    }
  
  
    // **** Internal methods below this line ****
  
    TransferSyntax get _ts => rootDS.transferSyntax;
  
    bool get isEVR => rootDS.isEVR;
  
    bool get _isEncapsulated => _ts.isEncapsulated;
  
  /*
    int get _endOfBD => bd.lengthInBytes;
  */
  
    void _endOfBDError(int end) {
      throw 'EndOfBD length($end) _wIndex($_wIndex}) LIBytes(${bd
          .lengthInBytes})';
    }
  
    bool _hasRemaining(int n) {
      if ((_wIndex + n) >= bd.lengthInBytes) _endOfBDError(_wIndex + n);
      return true;
    }
  
    /// Writes a byte (Uint8) value to the output [bd].
    void _writeUint8(int value) {
      assert(value >= 0 && value <= 255, 'Value out of range: $value');
      bd.setUint8(_wIndex, value);
      _wIndex++;
    }
  
    /// Writes a 16-bit unsigned integer (Uint16) value to the output [bd].
    void _writeUint16(int value) {
      assert(value >= 0 && value <= 0xFFFF, 'Value out of range: $value');
      bd.setUint16(_wIndex, value, Endianness.HOST_ENDIAN);
      _wIndex += 2;
    }
  
    /// Writes a 32-bit unsigned integer (Uint32) value to the output [bd].
    void _writeUint32(int value) {
      assert(value >= 0 && value <= 0xFFFFFFFF, 'Value out if range: $value');
      bd.setUint32(_wIndex, value, Endianness.HOST_ENDIAN);
      _wIndex += 4;
    }
  
    /// Writes [bytes] to the output [bd].
    void _writeBytes(Uint8List bytes) {
      int limit = bytes.length;
      for (int i = 0, j = _wIndex; i < limit; i++, j++) {
        bd.setUint8(j, bytes[i]);
      }
      _wIndex = _wIndex + limit;
    }
  
    /// Writes [bytes], which contains Code Units to the output [bd],
    /// ensuring that an even number of bytes are written, by adding
    /// a padding character if necessary.
    void _writeStringBytes(Uint8List bytes, [int padChar = kSpace]) {
      _writeBytes(bytes);
      if (bytes.length.isOdd) {
        bd.setUint8(_wIndex, padChar);
        _wIndex++;
      }
    }
  
    /// Writes an [ASCII] [String] to the output [bd].
    void _writeAsciiString(String s,
            [int offset = 0, int limit, int padChar = kSpace]) =>
        _writeStringBytes(ASCII.encode(s), padChar);
  
    /// Writes an [UTF8] [String] to the output [bd].
    void _writeUtf8String(String s, [int offset = 0, int limit]) =>
        _writeStringBytes(UTF8.encode(s), kSpace);
  
    // **** DICOM encoding stuff ****
  
  
  
  
    // There are four [Element]s that might have an Undefined Length value
    // (0xFFFFFFFF), [SQ], [OB], [OW], [UN]. If the length is the Undefined,
    // then it searches for the matching [kSequenceDelimitationItem] to
    // determine the length. Returns a [kUndefinedLength], which is used for
    // writeing the value field of these [Element]s. Returns an [SQ] [Element].
  
    /// writes an EVR or IVR Sequence. The _writeElementMethod detects Sequences.
  
  
  
    //TODO this can be moved to Dataset_base if we abstract DatasetExplicit
    // & writeElementExplicit
    /// Returns an [Item] or Fragment.
  
  
    static ByteData _reuseBD([int size = defaultBufferLength]) {
      if (_reuse == null) return _reuse = new ByteData(size);
      if (size > _reuse.lengthInBytes) {
        _reuse = new ByteData(size + 1024);
        log.warn('**** DcmWriter creating new Reuse BD of Size: ${_reuse
            .lengthInBytes}');
      }
      return _reuse;
    }
  
    /// Writes the [Dataset] to a [Uint8List]. Returns the [Uint8List].
    static Uint8List writeBytes(Dataset ds,
        {String path = "",
          bool fmiOnly = false,
          fast = false,
          TransferSyntax targetTS}) {
      if (ds == null || ds.length == 0)
        throw new ArgumentError('Empty ' 'Empty Dataset: $ds');
      var writer = (fast) ? new DcmByteWriter.fast(ds) : new DcmByteWriter(ds);
  