This discussion is archived
7 Replies Latest reply: Jan 15, 2013 12:56 AM by BluShadow RSS

utl_compress.lz_uncompress is unable to unzip a .7z file

984562 Newbie
Currently Being Moderated
Hi,

I have zip file zipped by 7z zipper in server, when i am trying to unzip it using utl_compress, its throwing an error telling to check the zip source.

can any1 help me with a sample code which shows how to unzip a .7z zip file using utl_compress.lz_uncompress.

thanks in advance

regards
anksh
  • 1. Re: utl_compress.lz_uncompress is unable to unzip a .7z file
    SomeoneElse Guru
    Currently Being Moderated
    The manual doesn't have much to say about utl_compress (and I've never used it) but it would appear that it can only uncompress something created with its own compress utility.

    I doubt it supports the 7-Zip format.

    You might have to call out to the OS to perform uncompressing that file.
  • 2. Re: utl_compress.lz_uncompress is unable to unzip a .7z file
    Marwim Expert
    Currently Being Moderated
    Hello,

    welcome to the forum.
    how to unzip a .7z zip file
    Is it a file compressed with the tool 7-Zip but in the .zip format or is it a file in .7z format?

    utl_compress can only handle a single file while the .zip format can contain many files, including filename and path information. To unzip a .zip file have a look at {message:id=4508157}.

    The .7z format is different and can only be uncompressed by 7-Zip itself or another tool that supports this format.


    Regards
    Marcus
  • 3. Re: utl_compress.lz_uncompress is unable to unzip a .7z file
    BluShadow Guru Moderator
    Currently Being Moderated
    LZ compression is based on the Lempel-Ziv compression algorithm.

    There are many other compression algorithms out there including LZW (Lempel-Ziv-Welch) which enhances the LZ algorithm, and is the basis for the compression used in .gif images, and then there are further enhancements to that algorithm, used in .zip files for the 'deflate' and other optional ways zip files can be produced.

    The 7zip product supports the standard LZ and LZW style compression algorithms, but also has it's own 'enhancement' which creates .7z files (7zip compression algorithm).
    There may be other products out there that support 7zip compression, but Oracle UTL_COMPRESS with it's basic LZ compression algorithm isn't one of them.

    Yes, it would be nice if Oracle could supply an updated compression package to deal with more, and better, compression algorithms, but then they'll potentially be getting into the patent issues around those.
  • 4. Re: utl_compress.lz_uncompress is unable to unzip a .7z file
    stefan nebesnak Journeyer
    Currently Being Moderated
    As BluShadow said, the zip file may be using any one of several compression algorithms.

    UTL_COMPRESS use LZ77 (Lempel-Ziv 1977) algorithm.

    You can use zipinfo Linux/Unix command to list detailed technical information about a ZIP archive - type of compression, encryption status and the like..

    You can also use java stored procedures (package java.util.zip) to solve this.
  • 5. Re: utl_compress.lz_uncompress is unable to unzip a .7z file
    984562 Newbie
    Currently Being Moderated
    i am compressing the file by 7z tool in .zip format and its a single file, i tried with winzip too but not succeded whn i debugged thn i found tht both 7z and winzip uses LZMA compression algo, whereas utl compress utility uses LZW algo so most probably thts the problem so i tried to unzip it using shell script but whn i am calling the shell script using dbmsscheduler its giving error no such file or directory found most probably i think because of root access issue, i tried to go for java code but i m not at all aware of any java stuffs so not able to figure out, i know tht i can get java code for this in net but without understanding it properly i dont want to use it... thts why posted the question in forum thought some1 may help me ... no i m trying to find a open source software which compress file based on LZW algo so tht the compatibility prblm can b removed.
  • 6. Re: utl_compress.lz_uncompress is unable to unzip a .7z file
    Marwim Expert
    Currently Being Moderated
    Did you read the thread I linked above? It has a link to http://technology.amis.nl/blog/8090/parsing-a-microsoft-word-docx-and-unzip-zipfiles-with-plsql. At the end of the post Anton Scheffer provides a link to a package that can zip and unzip files.
    This should work with regular ZIP files.
  • 7. Re: utl_compress.lz_uncompress is unable to unzip a .7z file
    BluShadow Guru Moderator
    Currently Being Moderated
    981559 wrote:
    i am compressing the file by 7z tool in .zip format and its a single file, i tried with winzip too but not succeded whn i debugged thn i found tht both 7z and winzip uses LZMA compression algo, whereas utl compress utility uses LZW algo so most probably thts the problem so i tried to unzip it using shell script but whn i am calling the shell script using dbmsscheduler its giving error no such file or directory found most probably i think because of root access issue, i tried to go for java code but i m not at all aware of any java stuffs so not able to figure out, i know tht i can get java code for this in net but without understanding it properly i dont want to use it... thts why posted the question in forum thought some1 may help me ... no i m trying to find a open source software which compress file based on LZW algo so tht the compatibility prblm can b removed.
    I think you need to speak with your hardware guys and get a new keyboard. It seems some of your keys are broken.

    7zip doesn't necessarily use LZMA compression, it depends which options you pick, it can use many .zip compatible formats and levels of compression.

    The Java implementation of zip isn't difficult to do in Oracle...
    CREATE OR REPLACE PACKAGE UTL_Zip IS
      /*                                                                                                                          */
      /* Database user must have java permissions to read,write,delete,execute the appropriate directories/files                  */
      /* e.g.                                                                                                                     */
      /*   dbms_java.grant_permission('MYUSER', 'SYS:java.io.FilePermission', '<<ALL FILES>>',  'read,write,delete,execute');     */
      /*   dbms_java.grant_permission('MYUSER', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', NULL);                   */
      /*   dbms_java.grant_permission('MYUSER', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', NULL);                  */
      /*                                                                                                                          */
      /*   NOTE: <<ALL FILES>> should not really be used.  Instead, specific directories should be given access                   */
      /*                                                                                                                          */
      /*   NOTE: O/S directories must allow Administrator to have read,write permissions to be able to create directories etc.    */
      /*                                                                                                                          */
      FUNCTION compressFile (p_in_file IN VARCHAR2, p_out_file IN VARCHAR2) RETURN BOOLEAN AS
        LANGUAGE JAVA NAME 'UTL_Zip.compressFile(java.lang.String,java.lang.String) return java.lang.Boolean';
    END;
    /
    
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "UTL_Zip" as
      import java.util.zip.*;
      import java.io.*;
      public class UTL_Zip
        {
          public static boolean compressFile(String infilename, String outfilename)
          {
            try
            {
              boolean infile_exists = (new File(infilename)).exists();
              if (!infile_exists) {
                return false;
              }
              FileOutputStream fout = new FileOutputStream(outfilename);
              ZipOutputStream zout = new ZipOutputStream(fout);
              ZipEntry ze = new ZipEntry((new File(infilename)).getName());
              boolean success;
              try
              {
                FileInputStream fin = new FileInputStream(infilename);
                zout.putNextEntry(ze);
                copy(fin, zout);
                zout.closeEntry();
                fin.close();
                success = true;
              }
              catch (IOException ie)
              {
                System.out.println("IO Exception occurred: " + ie);
                success = false;
              }
              zout.close();
              return success;         
            }
            catch(Exception e)
            {
              System.out.println("Exception occurred: " + e);
              return false;
            }
          }
          
          public static void copy(InputStream in, OutputStream out)
          throws IOException
          {
            byte[] buffer = new byte[4096];
            while (true) {
              int bytesRead = in.read(buffer);
              if (bytesRead == -1) break;
              out.write(buffer, 0, bytesRead);
            }
          }
        }
    /
    That just zips individual files, so there's more to it if you wanted to add multiple files to a zip archive etc.

Incoming Links

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points