LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Storing into a string the content of a folder using zip compression

Solved!
Go to solution

HI to all,

I'm currently looking for a solution on how to store in a database field the content of a folder.

my idea is to compress the folder I want to store into the db into a zip file... then read the zip file like a text file and store the resulting string.

 

by now the main problem is to convert the zip file I create to a string and back.

 

if I simply read the zip file and re-write it into another zip file i obtain that the second file is corrupted.

 

my guess is that I'm not able to properly read the zip file... does anyone have advice?

0 Kudos
Message 1 of 14
(1,438 Views)

I'd be interested in seeing some code.  Because what you described should be possible.  As long as the database can store nulls without treating it like a string I think you should be fine.  It will just end up being an array of bytes that you can read, save to a temp location, and then open as a normal zip.  I'm interested in seeing how you are reading and writing the zip file.  Are you using the read from text file?  Do you have Convert EOL on these nodes?  They are on by default and can modify your read or write.  The Read/Write binary file might be a better option.  Also maybe compare the string value in the database, to the hex representation of the zip file before storing it.  How are they different?

0 Kudos
Message 2 of 14
(1,429 Views)

here is my unit test code

 

basically i select a folder and the vi creates a zip file "original" (which is not corrupted) then the vi tries to read the zip as a text and then re build a new zip file... which is corrupted😓

0 Kudos
Message 3 of 14
(1,423 Views)

Can't see your code, 21 is too new for me.

 

Is Convert EOL off (right click the file function used to read and write)?

 

0 Kudos
Message 4 of 14
(1,382 Views)

Immagine 2022-07-13 181756.png

0 Kudos
Message 5 of 14
(1,379 Views)

convert EOL is on

0 Kudos
Message 6 of 14
(1,378 Views)

 


@francescofabbro wrote:

convert EOL is on


That’s wrong! Disable it or use the Read Binary and Write Binary File functions instead!
A ZIP is a binary stream formaf and should never be read and written in text mode.

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 14
(1,361 Views)

If you use "Write to binary file" remember to always turn off "prepend array or string size", otherwise you get 4 bytes at the front you weren't expecting.

Kyle97330_0-1657743864479.png

 

0 Kudos
Message 8 of 14
(1,348 Views)

hi,

I tried to put on false that input but nothing changes.

can it be a matter of encoding?

 

0 Kudos
Message 9 of 14
(1,330 Views)

ZIP files are binary. There is no character encoding involved at any stage as far as the overall structure of a ZIP file is involved. There are text elements inside ZIP archives that COULD involve encoding but they have no influence on the level you are working here.

 

Try to not just see if the strings (really byte arrays but in LabVIEW these are unfortunately still the same things) are the same, but where they actually differ. Length, what bytes are different and so on. That will give you (or at least us) a clue to what might be the problem. 

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 14
(1,321 Views)