ning / compress

High-performance, streaming/chunking Java LZF codec, compatible with standard C LZF package
Other
254 stars 40 forks source link

Command-line tool out of memory #12

Closed nodarret closed 12 years ago

nodarret commented 13 years ago

For big files better way is use Input/Output Streams. Very useful will be to add parametr sending results into standard output.

Example: -d parameter: decompress to file -c parameter: compress to file -o parameter: decompress to output

Example Java code:

void process(String[] args) throws IOException
    {
        if (args.length == 2) {
            String oper = args[0];
            boolean toSystemOutput = false;
            boolean compress = "-c".equals(oper);
            if ("-o".equals(oper)) {
                toSystemOutput = true;
            }
            if (compress || "-d".equals(oper) || "-o".equals(oper)) {
                String filename = args[1];
                File src = new File(filename);
                if (!src.exists()) {
                    System.err.println("File '"+filename+"' does not exist.");
                    System.exit(1);
                }
                if (!compress && !filename.endsWith(SUFFIX)) {
                    System.err.println("File '"+filename+"' does end with expected suffix ('"+SUFFIX+"', won't decompress.");
                    System.exit(1);
                }

                InputStream is;
                OutputStream out;

                if (!compress) {
                    is = new LZFFileInputStream(src);
                    if (toSystemOutput) {
                        out = System.out;
                    } else {
                        out = new FileOutputStream(new File(filename.substring(0, filename.length() - SUFFIX.length())));
                    }
                } else {
                    is = new FileInputStream(src);
                    out = new LZFFileOutputStream(new File(filename+SUFFIX));
                }

                byte[] buffer = new byte[8192];
                int bytesRead = 0;
                while ((bytesRead = is.read(buffer, 0, buffer.length)) != -1) { 
                    out.write(buffer, 0, bytesRead); 
                }
                out.flush();
                out.close();

                return;
            }
        }
        System.err.println("Usage: java "+getClass().getName()+" -c/-d/-o file");
        System.exit(1);
    }
cowtowncoder commented 13 years ago

Sounds like a useful improvement -- command-line tool was implement in minimal way, and definitely should be possible to add incremental encoder/decoder.

cowtowncoder commented 12 years ago

Took quite a while, but finally remembered to implement, along with a minor new feature; will be published as 0.9.3.