1

I'm using Electron, Githubs desktop framework built using JS and HTML 5. I need to check if fileA is different to fileB, and similarly with 2 strings.

These files and strings could be of equal size but be different. They could be small (2-3 bytes) or large (2-3 megabytes).

The nature of the app means I'll need to check this every half second or so (I have some leeway with the polling time).

This data is stored in a local database, similar to sqlite. I have full control over what's in this database. My initial thought is to create and store an MD5 hash of each file/string in the database along with the mime type and size of the file/string. That way I can check for differences in size, then fallback to mime type if size is the same, and then md5 if size is the same.

My problem is the polling frequency. In a nutshell, I'm getting the clipboard contents and checking that against a db, so the size, mime type and md5 hash will need to be calculated at each poll. Mime type and size should be OK, but md5ing a 8MB image might get slow.

Is there another method I should be aware of?

Thanks

Mike
  • 8,767
  • 8
  • 49
  • 103
  • "but md5ing a 8MB image might get slow" have you actually tested this? because it's somewhat created with speed in mind. – PeeHaa Mar 31 '16 at 21:10
  • @PeeHaa: I have, and it's quick, but I'm on a very high end machine. I just want to be sure I'm tackling this the best and most efficient way possible, especially as I wish to distribute this app – Mike Mar 31 '16 at 21:13
  • As @Jan Viehweger suggests below, can you just use [ClipboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent)s to tell when there's a new file in the clipboard rather than polling? – Noah Freitas Mar 31 '16 at 21:25
  • I'm not sure they're available in Chromium. No mention is made in the docs and there have been a few github issues asking for clipboard events and the outcome is to poll – Mike Mar 31 '16 at 21:28
  • Do you need to know if the clipboard content has changed? – Jan Viehweger Mar 31 '16 at 21:09
  • @JanViehweger: In effect, yes. There's no event for that though, hence I need to check periodically if old is different to new, or if they're the same – Mike Mar 31 '16 at 21:12
  • B.t.w. why could observe the ClipboardEvent.copy – Jan Viehweger Mar 31 '16 at 21:19
  • I do not understand, why you need to hash both files 2 times a second. Initial check at the beginning and a check if one file changes. And there must be an event when a file changes. If you are using a database you could generate the hash when you write or update an entry. – apxp Apr 01 '16 at 07:33

0 Answers0