{"id":20186041,"url":"https://github.com/neosmart/streamcompare","last_synced_at":"2025-04-10T06:22:04.679Z","repository":{"id":39706737,"uuid":"191479036","full_name":"neosmart/StreamCompare","owner":"neosmart","description":"A .NET library and nuget package for stream comparison.","archived":false,"fork":false,"pushed_at":"2022-05-27T15:41:57.000Z","size":43,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T07:27:04.668Z","etag":null,"topics":["csharp","netstandard13","netstandard20","nuget"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neosmart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-12T02:00:20.000Z","updated_at":"2022-09-26T20:28:58.000Z","dependencies_parsed_at":"2022-07-20T13:32:18.918Z","dependency_job_id":null,"html_url":"https://github.com/neosmart/StreamCompare","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neosmart%2FStreamCompare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neosmart%2FStreamCompare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neosmart%2FStreamCompare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neosmart%2FStreamCompare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neosmart","download_url":"https://codeload.github.com/neosmart/StreamCompare/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166865,"owners_count":21058481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","netstandard13","netstandard20","nuget"],"created_at":"2024-11-14T03:15:46.112Z","updated_at":"2025-04-10T06:22:04.640Z","avatar_url":"https://github.com/neosmart.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StreamCompare by NeoSmart Technologies\n\n`StreamCompare` is a .NET library and NuGet package for efficient comparison of `Stream` objects,\nchecking for the equality of the data they contain. `StreamCompare` is compatible with .NET Standard\n1.3 and above.\n\n## What's this for?\n\nA `Stream` in .NET is somewhat of an ornery object given that it typically abstracts away IO\noperations that may or may not be otherwise directly accessible. If you need to check if two files\nor network resources are byte-for-byte equivalent, strategies like hashing and digests [only make\nsense](http://neosmart.net/blog/2019/compare-streams-nuget/) if you plan on comparing against the\nsame file more than (at least) once. If you have a one-off comparison to make between two files or\nstreams, it's always more efficient to simply compare their contents byte-by-byte until you find a\nmismatch (or don't).\n\n`StreamCompare` does this for you, and abstracts away all the edge cases and performance pitfalls.\nWe've strived to make it as simple and straight-forward to use as possible.\n\nRead more about `StreamCompare` in [the official release\narticle](http://neosmart.net/blog/2019/compare-streams-nuget/).\n\n## License and authorship\n\n`StreamCompare` is released to the general public under the terms of the MIT public license in hopes\nthat it is helpful in writing more efficient and sound code. `StreamCompare` was developed by\nMahmoud Al-Qudsi of NeoSmart Technologies, factored out of code we've written in the past for some\nof our IO-heavy projects.\n\n## Installation\n\n`StreamCompare` is [available on NuGet](https://www.nuget.org/packages/StreamCompare/) and may be\ninstalled by executing the following in the Visual Studio Package Manager:\n\n```\nInstall-Package StreamCompare\n```\n\n## Usage\n\n`StreamCompare` is extremely straightforward to use. The `new\nNeoSmart.StreamCompare.StreamCompare()` creates a new `StreamCompare` instance that may be used to\ncompare two `Stream`s. Reuse of `StreamCompare` objects is encouraged where possible (a single\n`StreamCompare` instance should be used by one and only one thread at a time).\n\n### `StreamCompare`\n\nThis is the core object used for comparison of `Stream` objects for equality. It may (should) be\nreused to minimize buffer allocations where possible.\n\n#### `StreamCompare()`\n\nCreates a new `StreamCompare` object with the default settings. The static\n`StreamCompare.DefaultBufferSize` property indicates what buffer size should be used.\n\n#### `StreamCompare(uint bufferSize)`\n\nCreates a new `StreamCompare` object with the specified buffer size, used instead of\n`StreamCompare.BufferSize`.\n\n#### `StreamCompare.AreEqualAsync(Stream stream1, Stream stream2, CancellationToken cancel, bool? forceLengthCompare)`\n\nCompares two `Stream` instances for bytewise equality. The comparison aborts when the first\ndifference between the two streams is encountered. Streams are read in parallel where/when possible.\n\n* `Stream stream1`: The first `Stream` instance to read from for comparison\n* `Stream stream2`: The second `Stream` resource to read from for comparison\n* `CancellationToken cancel`: The optional `CancellationToken` to be used to terminate IO\n  operations. `CancellationToken.None` is used if this is not provided.\n* `bool? forceLengthCompare`: Tri-state determining whether or not `Stream.Length` is first checked\n  for equality between the two `Stream` instances. When not set or set to `null`, a heuristic is\n  used to guess whether or not `Stream.Length` can be safely accessed to short-circuit stream\n  comparison when the `Stream` instances differ in length.\n\n### `FileCompare`\n\n`FileCompare` is a convenience wrapper around `StreamCompare` that can be used to compare two files\nfor equality via their paths. It may (should) be reused to minimize buffer allocations where possible.\n\n#### `FileCompare()`\n\nCreates a new `FileCompare` object used to compare the contents of files via their relative or\nabsolute paths on the filesystem. A `StreamCompare` object is constructed with the default settings\nand buffer sizes under the hood.\n\n#### `FileCompare(uint bufferSize)`\n\nCreates a new `FileCompare` object used to compare the contents of files via their relative or\nabsolute paths on the filesystem. The specified `bufferSize` is passed to the constructor of\n`StreamCompare` to be used as the underlying buffer size.\n\n#### `FileCompare.AreEqualAsync(string path1, string path2, CancellationToken cancel)`\n\nThe main entry point for comparing the contents of two files. It contains some optimizations for\nshort-circuiting stream comparison in cases where the equality of the files can be determined\nwithout opening them for read.\n\n* `string path1`: The absolute or relative path to the first file to compare\n* `string path2`: The absolute or relative path to the second file to compare\n* `CancellationToken cancel`: The optional `CancellationToken` to use for IO operations for early\n  termination. When not supplied, `CancellationToken.None` is used instead.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneosmart%2Fstreamcompare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneosmart%2Fstreamcompare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneosmart%2Fstreamcompare/lists"}