-1

I am trying to make an app that uses a bunch text files as a base for most of its actions and this text files can be updated from a web server.
Currently my app is able to download a batch of text files via a zipped archive, but I was wondering if there was a way to check if I already had the contents of the zip file before downloading them.
What I had now was that I would download and unzip followed by a line by line check to see if the current files where different from the recently downloaded files.
This is seemingly very inefficient but I do not know of any other way.
If anybody has any suggestions and can either give a small example or point me to one I would greatly appreciate it.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
blu
  • 353
  • 1
  • 5
  • 17
  • 1
    You can store the last time you did download the file on your SharedPreferences and then do a callback on your webservice to return the last time the file you need to download was altered, do you have control over the webservice? – GhostDerfel Feb 12 '14 at 20:17
  • 3
    If you can edit files on the server, add a file which calculates an hash for the zip file: this way you can compare the server hash with the hash of the zip file you already have. If the two are equal, then your zip is up to date, if they aren't, you need to re-download the file – BackSlash Feb 12 '14 at 20:17
  • http includes a mechanism for that. use if-modified-since and check for 304 response. – njzk2 Feb 12 '14 at 20:19
  • 1
    Also you can do something like @BackSlash say, but will be better if you can store only the hash and have a call to return this hash on your webservice, so you don't need to do the download just to check the file – GhostDerfel Feb 12 '14 at 20:20
  • @GhostDerfel It's exactly what I'm saying – BackSlash Feb 12 '14 at 20:22
  • unfortunately i cannot edit the web server in anyway,i can only pull the compressed text files from a web server, but the use of a hash might come in handy. – blu Feb 12 '14 at 20:51

1 Answers1

0

To assemble what BackSlash and the others already said in the comments:

One possible solution could be to:

  1. Create a hash of the file when the file is being created (good) or after download (bad)
  2. Store this hash somewhere (e.g. inside the filename instructions-d41d8cd98f00b204e9800998ecf8427e.zip)
  3. Client: Query the server with the string
  4. Server: Check the transmitted hash against the hash of the newest version
  5. Server: Respond accordingly (e.g by using the HTTP built-in 304 response)
  6. Client: Act upon the response of the server
Community
  • 1
  • 1
Nick Russler
  • 4,608
  • 6
  • 51
  • 88
  • i cannot create or modify the files already on the server only download them. would it be possible to request the file size of the zip file through some android magic i am unaware of? – blu Feb 12 '14 at 20:53
  • In general the filesize is not unique, but if you still want to use it you can check whether the http server sends the file size in the header: http://stackoverflow.com/a/2983420/441907 – Nick Russler Feb 12 '14 at 20:54
  • You can also calculate the hash client side and send it to the server (which you would need to adapt to support your query). You should then store the hash somewhere so you do not need to recalculate it. Create it after download. – Nick Russler Feb 12 '14 at 21:06
  • If i can calculate the hash on the android device prior to actually downloading the files then this might solve my problem. i can simply store the checksum on the device and compare a history of checksums to what is on the server before download. – blu Feb 13 '14 at 15:33