working on it ...

Filters

Explore Public Snippets

Sort by

Found 6,425 snippets matching: zip

    public by sTiLL-iLL @ SniPitz-KND  3625  2  7  13

    ZipStich.cs !!! dont be a dip, ZIP n STITCH!!! NO 3rd party dependancy! .Net 3.5 and greater

    archive just a file or a whole directory. YEAH!
    using System;
    
    // usage demo....
    	public class Program
    	{
    		static void Main(string[] args)
    		{
    			ZipShitz zip = new ZipShitz(@"c:\test.zip", @"c:\TestFolder\");
    			zip.OnZipDone += zip_OnZipDone;
    			zip.ZipShitAsync(new Action(sayIt));
    		}
    
    		static void zip_OnZipDone(System.IO.Packaging.Package pakage, Action callbak)
    		{
    			callbak.Invoke();
    		}
    
    		static void sayIt()
    		{
    			Console.WriteLine("");
    			Console.WriteLine(">> All Files Zipped and Complete! <<");
    			Console.Read();
    		}
    	}
    	
    // end demo....
    	
    	
    	
    // using System;
    using System.IO;
    using System.IO.Packaging;
    using System.Text;
    using System.Threading.Tasks;
    
    
    public class ZipShitz
    {
    
    	public delegate void ZipCompleteHandler(Package pakage, Action callbak);
    	public event ZipCompleteHandler OnZipDone;
    
    
    	public string ZipName
    	{
    		get;
    		set;
    	}
    
    
    
    	public string TargetFolder
    	{
    		get;
    		set;
    	}
    
    
    
    	public ZipShitz(string zName, string trgt)
    	{
    		OnZipDone += ZipShitz_OnZipDone;
    		ZipName = zName;
    		TargetFolder = trgt;
    	}
    
    
    
    	public ZipShitz()
    	{
    		OnZipDone += ZipShitz_OnZipDone;
    	}
    
    
    
    	void ZipShitz_OnZipDone(Package pakg, Action cbak)
    	{
    		if (!cbak.Equals(null))
    		{
    			cbak.DynamicInvoke();
    		}
    
    		OnZipDone -= ZipShitz_OnZipDone;
    	}
    
    
    
    	public void ZipShit()
    	{
    		using (var pkg = ZipPackage.Open(ZipName, FileMode.Create))
    		{
    			foreach (var fila in Directory.GetFiles(TargetFolder, "*.*", SearchOption.AllDirectories))
    			{
    				try
    				{
    					Console.WriteLine("Packing " + fila);
    					Uri relUri = MapRelativePath(fila);
    
    					var pkgPart = pkg.CreatePart(relUri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum);
    					using (var fstrm = new FileStream(fila, FileMode.Open, FileAccess.Read))
    					{
    						StreamClone(fstrm, pkgPart.GetStream());
    					}
    				}
    				catch (Exception x)
    				{
    					throw x;
    				}
    			}
    		}
    	}
    
    
    
    	public void ZipShitAsync(Action assbak = null)
    	{
    		Package pkg = null;
    		Task.Factory.StartNew(() =>
    		{
    			using (pkg = ZipPackage.Open(ZipName, FileMode.Create))
    			{
    				foreach (string fila in Directory.GetFiles(TargetFolder, "*.*", SearchOption.AllDirectories))
    				{
    					try
    					{
    						Console.WriteLine("Packing " + fila);
    						Uri relUri = MapRelativePath(fila);
    						var pkgPart = pkg.CreatePart(relUri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum);
    						using (FileStream fstrm = new FileStream(fila, FileMode.Open, FileAccess.Read))
    						{
    							StreamClone(fstrm, pkgPart.GetStream());
    						}
    					}
    					catch (Exception x)
    					{
    						x = null;
    					}
    				}
    			}
    		}).Wait();
    
    		if (!OnZipDone.Equals(null))
    		{
    			this.OnZipDone.DynamicInvoke(pkg, assbak);
    		}
    	}
    
    
    
    	void StreamClone(Stream src, Stream tgt)
    	{
    		try
    		{
    			const int bufLen = 16384;
    			byte[] buf = new byte[bufLen];
    			int bytz = 0;
    			while ((bytz = src.Read(buf, 0, bufLen)) > 0)
    			{
    				tgt.Write(buf, 0, bytz);
    			}
    		}
    		catch (Exception x)
    		{
    			throw x;
    		}
    	}
    
    
    
    	Uri MapRelativePath(string fil)
    	{
    		Uri pth2 = null;
    
    		try
    		{
    			var rlPth = fil.Substring(fil.IndexOf('\\')).Replace('\\', '/').Replace(' ', '_');
    			pth2 = new Uri(CleanString(rlPth), UriKind.Relative);
    		}
    		catch (Exception x)
    		{
    			throw x;
    		}
    
    		return pth2;
    	}
    
    
    
    	string CleanString(string argz)
    	{
    		byte[] bytz = null;
    
    		try
    		{
    			string nrmz = argz.Normalize(NormalizationForm.FormKD);
    			Encoding ecdr = Encoding.GetEncoding(Encoding.ASCII.CodePage, new EncoderReplacementFallback(""), new DecoderReplacementFallback(""));
    			bytz = ecdr.GetBytes(nrmz);
    		}
    		catch (Exception x)
    		{
    			throw x;
    		}
    
    		return Encoding.ASCII.GetString(bytz);
    	}
    }
    
                                                                

    public by lbottaro  3949  1  7  0

    How to list the contents of a compressed file

    This code shows how to list the contents of a tar, tar.gz or tar.bz2 compressed file. Options: -t: List the contents of an archive -v: Verbosely list files processed (display detailed information) -z: Filter the archive through gzip so that we can open compressed (decompress) .gz tar file -j: Filter archive through bzip2, use to de
    # List the contents of a tar file
    tar -tvf file.tar
    
    # List the contents of a tar.gz file
    tar -ztvf file.tar.gz
    
    # List the contents of a tar.bz2 file
    tar -jtvf file.tar.bz2
    
    

    public by lbottaro  2864  1  7  3

    Extract or Unpack a TarBz2 File

    This code shows how to extract a tar bz2 file in linux. Command options: -x : Extract a tar ball. -v : Verbose output or show progress while extracting files. -f : Specify an archive or a tarball filename. -j : Decompress and extract the contents of the compressed archive created by bzip2 program (tar.bz2 extension).
    # This will extract the bz2 in a specific directory
    tar xvf file.tar.bz2 -C targetDirectory/
    
    # This will zip the directory into a file
    tar cvjf file.tar.bz2 targetDirectory/

    public by cghersi  3493  1  5  0

    Bash command to zip some content

    This command will zip the file file.txt and all the sh files contained in setup folder in a zip named myzip.zip. Then adds the file Third/otherfile.txt in then same archive with the last command
    ZIP_NAME="myzip.zip"
    zip "$SETUP_ZIP_DIR"/$ZIP_NAME setup/*.sh file.txt
    zip -g "$SETUP_ZIP_DIR"/$ZIP_NAME Third/otherfile.txt

    public by UdeF  2331  9  5  0

    Create 7zip archive with dialog

    Erstellt eine komprimierte 7z-Datei über Dialoge.
    #include <7Zip.au3>
    
    ;Exampe #1
    $ArcFile = FileSaveDialog("Create a new archive", "", "Archive Files (*.7z;*.zip;*.gzip;*.bzip2;*.tar)")
    If @error Then Exit
    
    $FileName = FileSelectFolder("Select a folder", "")
    If @error Then Exit
    
    $retResult = _7ZipAdd(0, $ArcFile, $FileName)
    If @error Then
    	MsgBox(64, "_7ZipAdd", "Error occurred")
    Else
    	MsgBox(64, "_7ZipAdd", "Archive created successfully" & @LF & _
    		   $retResult)
    EndIf

    public by marksimon232  4470  1  6  1

    How do you map over the values of Zip2 in Swift?

    foo has the type ZipGenerator2, IndexingGenerator?.
    The following will get you an array from the return value of Zip2:
    
    var myZip = Zip2([1, 2, 3], ["a", "b", "c"]).generate()
    var myZipArray: Array<(Int, String)> = []
    
    while let elem = myZip.next() {
        myZipArray += elem
    }
    
    println(myZipArray)    // [(1, a), (2, b), (3, c)]
    -- UPDATE: EVEN BETTER! --
    
    let myZip = Zip2([1, 2, 3], ["a", "b", "c"])
    let myZipArray = Array(myZip)
    
    println(myZipArray)    // [(1, a), (2, b), (3, c)]
    -- now for fun --
    
    I'm going to guess that we can init a new Array with anything that responds to generate() ?
    
    println(Array("abcde"))  // [a, b, c, d, e]

    public by Fresh-Dev  2707  4  3  0

    Zips every subdirectory as a seperate archive file.

    Zips every subdirectory as a seperate archive file.: zipSubdirectorys.bat
    FOR /D %%i IN (%1) 
        DO "c:\Program Files (x86)\7-Zip\7z.exe" a "%%i.zip" "%%i\"
    
    

    public by LongBeard  1792  0  3  0

    Zips every subdirectory as a seperate archive file.

    Zips every subdirectory as a seperate archive file.: zipSubdirectorys.bat
    FOR /D %%i IN (%1) 
        DO "c:\Program Files (x86)\7-Zip\7z.exe" a "%%i.zip" "%%i\"
    
    

    public by vdt  213  0  3  0

    Zipline example

    Zipline example: zipline_example.conf
    source: {
      type: hive
      query:"""
        SELECT
            id_listing as listing
          , dim_city as city
          , dim_country as country
          , dim_is_active as is_active
          , CONCAT(ds, ' 23:59:59.999') as ts
        FROM
          core_data.dim_listings
        WHERE
          ds BETWEEN '{{ start_date }}' AND '{{ end_date }}'
      """
      dependencies: [core_data.dim_listings]
      is_snapshot: true
      start_date: 2010-01-01
    }
    features: {
      city: "City in which the listing is located."
      country: "Country in which the listing is located."
      is_active: "If the listing is active as of the date partition."
    }
    
    

    public by cghersi  6918  6  9  5

    How to open a dockable window in Notepad++ in C#

    This code has been refined thanks to the hints given in the Plugin Tutorial Demo that can be found here: https://sourceforge.net/projects/sourcecookifier/files/other%20plugins/NppPlugin.NET.v0.5.zip/download
    public static void OpenForm(Form form, string title, int dialogID)
    {
        NppTbData _nppTbData = new NppTbData();
        _nppTbData.hClient = form.Handle;
        _nppTbData.pszName = title;
    
        // the dlgDlg should be the index of funcItem where the current function pointer is in
        _nppTbData.dlgID = dialogID;
    
        // define the default docking behaviour
        _nppTbData.uMask = NppTbMsg.DWS_DF_CONT_RIGHT | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR;
        //_nppTbData.hIconTab = (uint)tbIcon.Handle;
        _nppTbData.pszModuleName = PluginName;
        IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
        Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);
    
        try
        {
            SendMessage(nppData._nppHandle, NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData);
        }
        catch (Exception exc)
        {
            if (log != null)
                log.ErrorFormat("Cannot open form due to {0}", exc.Message);
        }
    }
    
    
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct NppTbData
    {
        public IntPtr hClient;            // HWND: client Window Handle
        public string pszName;            // TCHAR*: name of plugin (shown in window)
        public int dlgID;                // int: a funcItem provides the function pointer to start a dialog. Please parse here these ID
        // user modifications
        public NppTbMsg uMask;                // UINT: mask params: look to above defines
        public uint hIconTab;            // HICON: icon for tabs
        public string pszAddInfo;        // TCHAR*: for plugin to display additional informations
        // internal data, do not use !!!
        public RECT rcFloat;            // RECT: floating position
        public int iPrevCont;           // int: stores the privious container (toggling between float and dock)
        public string pszModuleName;    // const TCHAR*: it's the plugin file name. It's used to identify the plugin
    }
    
    
    [DllImport("user32")]
    public static extern IntPtr SendMessage(IntPtr hWnd, NppMsg Msg, int wParam, IntPtr lParam);
    
    • Public Snippets
    • Channels Snippets