#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    1
    Rep Power
    0

    Problem in zipping of files


    Hello,

    I am trying to zip some files (which make up an sxw file) inorder to get the sxw(Open office text document format). The zip part is working fine, the zipped file does not open in OpenOffice in its original form. I have found the contents to be the same as the original after unzipping this file.
    Could some one please help me with this.
    The code used is as follows:
    Code:
    zip_output_stream =  ZipOutputStream(FileOutputStream("test.sxw")) 
    try:
          #create a File object based on the directory we have to zip
          zip_dir = File(dir_to_zip)
    			
          dir_list = zip_dir.list()
    
          #loop through dir_list, and zip the files
          i = 0
          while i < len(dir_list):
    
    	f = File(zip_dir, dir_list[i])
    	i = i + 1
    	if f.isDirectory():
    		#if the File object is a directory, call this
    		#function again to add its content recursively
    		file_path = f.getPath()
    		self.zip_dir(file_path, zip_output_stream)
    		#loop again
    		continue
    	#if the File object f was not a directory
    	#create a FileInputStream on top of f
    	file_input_stream = FileInputStream(f)
    	#create a new zip entry
    	entry = ZipEntry(f.getPath())
    	#place the zip entry in the ZipOutputStream object 
    	zip_output_stream.putNextEntry(entry)
    	#write the content of the file to the ZipOutputStream 
    	buffer = jarray.zeros(1024,"b")
    	bytes_read = file_input_stream.read(buffer)
    	while  bytes_read != -1:
    		zip_output_stream.write(buffer, 0, bytes_read)
    		bytes_read = file_input_stream.read(buffer)
    		#close the Stream 
    		file_input_stream.close()
    		zip_output_stream.closeEntry()
          zip_output_stream.close()
    except ZipException:
    	return 0
    Thanks
    Last edited by netytan; May 27th, 2005 at 03:28 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    25
    this is just a idea of mine, i am not sure if this is your problem but: Openoffice file types are a mixter of xml and ziping. Possible when you unzip you are unziping the contents of the file type itself as well.
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Could you please repost your code using CODE tags as described in the sticky at the top of this and many other forums . As it stands it isn't easy to s to read your program above.

    Take care,

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Netytan, since you're a moderator, can't you edit his post?
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by †Yegg†
    Netytan, since you're a moderator, can't you edit his post?
    I can, and have in this case however I find it much more helpful to the user if they correct the post themselves. Once uppon a time I'd add code tags to all the posts like this but the same users would keep posting without them.

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo