Ensure byte-for-byte results when reading and then writing a file.

Review Request #11763 — Created July 31, 2021 and submitted

Information

DiffX
master

Reviewers

When reading a DiffX file using the DOM and then writing it back out,
the contents of the file would change. Since DiffX files are intended to
be a mutable format, we don't want to make any unwanted changes.

There were a few problems leading to this:

1) When reading into a file into a DiffX object, default options would
be preserved. This is really a problem for the main encoding
option, which would default to UTF-8 if missing in the DiffX file
content, and would then be written back out. Now, options are cleared
out before they're set.

2) Similarly, if an explicit main encoding value wasn't provided, the
default in DiffXWriter would be used. We now explicitly pull out
the encoding option, defaulting to None if not found in the file,
and pass it in to DiffXWriter.

2) DiffXWriter was hard-coding the version being set, and the DOM
therefore wasn't setting a version when writing. Now it will accept
a provided version. While not important right now, this will be
important for compatibility with future spec versions. It's up to
the caller to ensure the version being provided is valid.

Unit tests were added to ensure that we now get byte-for-byte results.

Unit tests pass.

Summary ID
Ensure byte-for-byte results when reading and then writing a file.
When reading a DiffX file using the DOM and then writing it back out, the contents of the file would change. Since DiffX files are intended to be a mutable format, we don't want to make any unwanted changes. There were a few problems leading to this: 1) When reading into a file into a `DiffX` object, default options would be preserved. This is really a problem for the main `encoding` option, which would default to UTF-8 if missing in the DiffX file content, and would then be written back out. Now, options are cleared out before they're set. 2) Similarly, if an explicit main encoding wasn't provided, the default in `DiffXWriter` would be used. We now explicitly pull out the `encoding` option, defaulting to `None`, and pass it in to `DiffXWriter`. 2) `DiffXWriter` was hard-coding the version being set, and the DOM therefore wasn't setting a version when writing. Now it will accept a provided version. While not important right now, this will be important for compatibility with future spec versions. It's up to the caller to ensure the version being provided is valid. Unit tests were added to ensure that we now get byte-for-byte results.
94542e32e0eee42a25e830aedfc2c9790609b5db
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to master (d88e782)