phonegap / phonegap-plugin-contentsync

Download and cache remotely hosted content
Apache License 2.0
206 stars 98 forks source link

Fix Windows unarchiving memory issues #165

Closed rbliss closed 7 years ago

rbliss commented 7 years ago

The current version of the plugin for Windows uses an unzip technique that requires copying each entire file in the zip archive into memory, before writing the file to disk. This works fine on small files, but causes the application to crash with an Out of Memory exception on larger files.

Since all the Windows file reading and writing uses streams, the change in this pull request removes the unnecessary reading of the file stream into a memory buffer and instead directly pipes the zip entry file to the output stream using CopyToAsync letting Windows handle the copy. This also has the benefit of being asynchronous, removes the memory loading step, and is simpler code overall.

I've successfully copied gigabyte files with almost no memory impact. I've tested this under Windows 10 only, however MSDN lists CopyToAsync as being available since Windows Phone 8.1 and Universal Windows Platform 8.

rbliss commented 7 years ago

Sorry for some of the noise in the commit, my editor also removed some trailing whitespace.

macdonst commented 7 years ago

@timkim @purplecabbage can you take a look at this PR?

timkim commented 7 years ago

I'm good to go for this merge as well. Merging in now.