Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for stream #12

Open
angedelamort opened this issue Jan 21, 2019 · 4 comments
Open

Support for stream #12

angedelamort opened this issue Jan 21, 2019 · 4 comments
Assignees

Comments

@angedelamort
Copy link

I was wondering if you could add support for FileStream (or Stream in general)?

Since we usually use files for computing the CRC, I find it annoying to load the file in memory in order to get all the bytes. When you have big files, it's not really good practice. And I saw that most of libraries use the same interface as yours.

So, that's what I can do right now:

var bytes = File.ReadAllBytes(path);
var crc32 = Crc32Algorithm.Compute(bytes);

What would be nice:

using (var stream = new FileStream(path, FileMode.Open))
{
    var crc32 = Crc32Algorithm.Compute(stream);
}

Thanks

@InvisiblePhil
Copy link

I happened to need/want this too, so see #14 if you want to try out my proposed implementation

@force-net
Copy link
Owner

Will check it later. Thank you.

@kgamecarter
Copy link

you can

using (var stream = new FileStream(path, FileMode.Open))
using (var crc = new Crc32Algorithm())
{
    var crc32bytes = crc.Compute(stream);
    var crc32 = BitConverter.ToUInt32(crc32bytes, 0);
}

@InvisiblePhil
Copy link

Doh, didn't realise the base class did that.
Looking at the source it's very similar to what I hacked together (right down to the 4kb buffer size).
Closing my PR as redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants