Esempio n. 1
0
Handle<Value> Zipper::New(const Arguments& args)
{
    HandleScope scope;

    if (!args.IsConstructCall())
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args.Length() != 1 || !args[0]->IsString())
        return ThrowException(Exception::TypeError(
          String::New("first argument must be a path to a zipfile")));

    std::string input_file = TOSTR(args[0]);
    struct zip *za;
    int err;
    char errstr[1024];
    if ((za=zip_open(input_file.c_str(), ZIP_CREATE, &err)) == NULL) {
        zip_error_to_str(errstr, sizeof(errstr), err, errno);
        std::stringstream s;
        s << "cannot open file: " << input_file << " error: " << errstr << "\n";
        return ThrowException(Exception::Error(
            String::New(s.str().c_str())));
    }

    Zipper* zf = new Zipper(input_file);
    zf->archive_ = za;
    zf->Wrap(args.This());
    return args.This();

}
Esempio n. 2
0
int main()
{
  Zipper demo;
  string str;
  str = demo.zipString("aabcccaaa");
  cout<<str<<endl;
  return 0;
}
Esempio n. 3
0
Handle<Value> Zipper::addFile(const Arguments& args)
{
    HandleScope scope;

    if (args.Length() < 3)
        return ThrowException(Exception::TypeError(
          String::New("requires three arguments, the path of a file, a filename and a callback")));
    
    // first arg must be path
    if(!args[0]->IsString())
        return ThrowException(Exception::TypeError(
          String::New("first argument must be a file path to add to the zip")));
    
    // second arg must be name
    if(!args[1]->IsString())
        return ThrowException(Exception::TypeError(
          String::New("second argument must be a file name to add to the zip")));
    
    // last arg must be function callback
    if (!args[args.Length()-1]->IsFunction())
        return ThrowException(Exception::TypeError(
                  String::New("last argument must be a callback function")));
  
    std::string path = TOSTR(args[0]);
    std::string name = TOSTR(args[1]);
  
    Zipper* zf = ObjectWrap::Unwrap<Zipper>(args.This());
    zf->Ref();

    uv_work_t *req = new uv_work_t();
    closure_t *closure = new closure_t();

    // libzip is not threadsafe so we cannot use the zf->archive_
    // instead we open a new zip archive for each thread
    struct zip *za;
    int err;
    char errstr[1024];
    if ((za=zip_open(zf->file_name_.c_str() , ZIP_CREATE, &err)) == NULL) {
        zip_error_to_str(errstr, sizeof(errstr), err, errno);
        std::stringstream s;
        s << "cannot open file: " << zf->file_name_ << " error: " << errstr << "\n";
        zip_close(za);
        return ThrowException(Exception::Error(String::New(s.str().c_str())));
    }

    closure->zf = zf;
    closure->za = za;
    closure->error = false;
    closure->path = path;
    closure->name = name;
    closure->cb = Persistent<Function>::New(Handle<Function>::Cast(args[args.Length()-1]));
    req->data = closure;

    uv_queue_work(uv_default_loop(), req, _AddFile, (uv_after_work_cb)_AfterAddFile);
    return Undefined();
}
Esempio n. 4
0
int main(int argv, char* argc[])
{
    /*/  Suppotred args:
    //
    //    -pack, -unpack, -files, -path
    //
    /*/
    
    setlocale(LC_ALL,"Russian");
    cout<<endl<<"######################## ZIPPER ########################"<<endl<<endl;
    if(argv>1)
    {
        vector<string> files;
        string path = "";
        bool flag_fs = false, flag_path = false;
        char type[6];
        memset(type,0,6);
        for(int i=1;i<argv;i++)
        {
            if(strcmp(argc[i],"-pack")==0) { strcpy(type,"pack"); flag_fs=flag_path=false;}
            if(strcmp(argc[i],"-unpack")==0) { strcpy(type,"unpack"); flag_fs=flag_path=false;}
            if(strcmp(argc[i],"-path")==0) {flag_path=true; flag_fs=false; continue; }
            if(strcmp(argc[i],"-files")==0) {flag_fs=true; flag_path=false; continue; }

            if(flag_path) {path.assign(argc[i]); }
            if(flag_fs) files.push_back(string(argc[i]));

        }
        Zipper *zip = new Zipper(files,path);
        if(strcmp(type,"pack")==0) zip->InCompress();
        if(strcmp(type,"unpack")==0) zip->OutCompress(files[0]);
    }
    else cout<<"Параметры -pack/-unpack , -files, -path обязательны!"<<endl;
    cout<<endl<<"########################################################"<<endl<<endl;

}
Esempio n. 5
0
int main(){
	Zipper z ;
	string s("jjjjjjxxxxxxxooZLLLLLLLLQQQQQQQQQLLLLLLLLECXXXXXXXIIIIIIIIIhjjyyySSooooooooommmuuEEEEEEEEEnnnnnnnffffffAAAAAllllllllbbbbkkkkkkkkkkkkKKKKKKhhhhhhhhhooooooooooYCCCCCCOOOOOOOOOMMMMMMMMMMiiiiiivvvvvvvWWWWkkkkkkwwwwwwwMmmmmmmmmLLLwwwwwwwkkkjjjjjjttttQQQQQQQQQaaaaaaaFFFFFFFlllllllllggggggggggPPPPPPuuuuuuuuaYYYYYYwQQQFFFFFFFFFFaaaaapXXXXXXXxxxxxxQQQQQQQQQsssssGGGGfffffffddddddpppQQQQQQHHHTTTaaaaaaGGGGGGddyyyyyMhhllllllllllNNNNNNNNUUUWWWWWWLLLLLLLLLYYYYYYYYYYTTKKKKKKKKiiiiiiitttttttXXXXXXXXXLLLHZZZZZZZssssjjJJJEEEEEOOOOOttttttttttBBttttttTTTTTTTTTTrrrrttttRRRRRyyooooooaaaaaaaaarrrrrrrPPPPPPPjjPPPPddddddddddHHHHnnnnnnnnnnSSSSSSSSSSzzHHHHHHHHHddddddDDDzzzhhhhhfffffffffftttttteeeeeeeeEEEEEEEEEaaaaaaccccccccccFFFFFFFF");
	cout << z.zipString(s) << endl;
	return 0;
}