1

I am using DotNetZip library to zip my files programatically. The resultant zip file is then uploaded onto a server using SFTP.

My question is if there a way I can specify the order in which the files should be unzipped on the server.

I am not sure about the job which does the task of unzipping.

Edit: The zip consists of 100 documents (usually PDF) and 100 metadata files for each of these documents. The metadata files end with .metadata. A file with such an extension triggers a job on the server to look for the document referred by the metadata. I would like these .metadata files to be extracted from the zip after all the other normal files are extracted.

Nishant
  • 905
  • 1
  • 16
  • 36
  • 1
    Why would you waant to unzip in a particular order? The result is the same either way. – Anirudh Ramanathan Jul 12 '12 at 10:26
  • Apologies for being abstract. I have added an edit to the question. – Nishant Jul 12 '12 at 10:33
  • Do you have any control over the way decompression is done at the server-end? – Anirudh Ramanathan Jul 12 '12 at 10:35
  • 1
    A common approach for this sort of thing is often to extract to a temporary location, then move stuff to the pickup location afterwards. That way you shouldn't have the issues about half written files or ordering. – Jon Egerton Jul 12 '12 at 10:36
  • No I do not have any control over the server and the decompression mechanism. – Nishant Jul 12 '12 at 10:39
  • I'd go with @JonEgerton's solution. Extract to temporary location and then move the files around. – Anirudh Ramanathan Jul 12 '12 at 10:40
  • It's impossible to guarantee the order of unzipping if your don't have control of the unzipper. However, if the unzipper is simple - unzip from the beginning to the end then you might have a change: Simply zip the files in the order you want – Onkelborg Jul 12 '12 at 10:46

3 Answers3

0

While you cannot set order of extraction using ExtractAll method, you can get list of files in archive using Entries and use ExtractSelectedEntries to process them in order you need.
Update:

No I do not have any control over the server and the decompression mechanism

So it's not a problem of DotNetZip usage?.. OK, plan B: send metadata in another archive. But there might be problem with lack of synchronization of their unpacking.

Anirudh Ramanathan
  • 46,179
  • 22
  • 132
  • 191
alxx
  • 9,897
  • 4
  • 26
  • 41
0

I just tested this on my LAMP server. The decompression in my case occurs in the following. you need to test this on your server to find it in your case.

firstly
    Folders a,A,b,B....--->z (alphabetically)
secondly
    Files a,A,b,B....--->z (alphabetically)

Test the unzip order, in your case and name the metadata files such that they end up at the beginning or end of a list, as necessary.

Or as @Onkelborg said, in your case the unzip operation could just follow the zip order during extraction. No definitive way to tell without testing it first.

Even then, there could be multiple threads performing the operation and you could run into issues so the safest way is to unzip files+metadata to a temporary location and then move them in the right order.

Anirudh Ramanathan
  • 46,179
  • 22
  • 132
  • 191
  • This implies that case in file names doesn't matter (at least for those PDF's...) It seems all solutions except custom unzipper are flaky. – alxx Jul 12 '12 at 10:55
  • Just tested, with upper case filenames `extracting: abc.txt extracting: Abc.txt extracting: def.txt` – Anirudh Ramanathan Jul 12 '12 at 11:01
  • Am not sure about the alphabetical order you just mentioned. This is because I added 10 files with names (1.txt, 2.txt,3.txt,4.txt,5.txt,6.txt,7.txt,8.txt,9.txt,10.txt) in the same order. The result was random. Once it generated 10.txt second. – Nishant Jul 12 '12 at 11:17
  • First time it was random. Second time and subsequent times it followed. – Nishant Jul 12 '12 at 11:24
  • Did it follow the order in which you zipped the files up or was it completely random? Try adding a few directories along with the files. Do the directories always get extracted after the files? If it is unreliable, unzipping to a temporary location might be your best option. – Anirudh Ramanathan Jul 12 '12 at 11:24
0

A common approach for this sort of thing is often to extract to a temporary location, then move stuff to the pickup location afterwards.

That way you shouldn't have the issues about half written files or ordering, and any fails on unzipping don't leave the consumer with half a data set.

Jon Egerton
  • 40,401
  • 11
  • 97
  • 129