kr / binarydist

Go implementation of bsdiff & bspatch
http://godoc.org/github.com/kr/binarydist
MIT License
306 stars 40 forks source link

Passing channel to cancel a diff #7

Open amlwwalker opened 5 years ago

amlwwalker commented 5 years ago

Hello! This is a cool bit of work. I am looking to cancel a diff (on large files where the diff takes time), I want to pass a channel into the function that gets checked for a message (on a switch case) and if a value comes off the channel, it cancels the diff and stops in its tracks and cleans up.

My questions.

Where best to put the channel? I am thinking to fork your work.

There is the line of code: https://github.com/kr/binarydist/blob/190e7de772656c6127fa8e55c6258ed1b7eabcee/diff.go#L234-L240

I.e the

for scan < len(nbuf) { 

line of code.

If I pass a channel into this function, and then inside the for loop, do a switch case can I stop the diff safely and destroy whatever diffing has already occured and pass back a success message? Its just because on larger files diffing can take some time and I'd like to be able to stop it...

Thanks!

kr commented 5 years ago

Given the way binarydist is currently implemented, a fork sounds reasonable.

(I think it would be preferable for binarydist to write the diff directly to the given Writer (if it's also a Seeker) rather than to a buffer. If it did, you could have the Writer cancel the diff by returning an error. But of course that would require some changes to this library.)