INFO

This API documentation is for FAKE version 5.0 or later. The old API documentation can be found here for migration or here for fake 4

This is part of the Fake.IO.Zip module.

Zip

This module contains helper function to create and extract zip archives.

Functions and values

Function or valueDescription
createZip(...)
Signature: workingDir:string -> fileName:string -> comment:'?9751 -> level:int -> flatten:bool -> files:seq<string> -> unit
Type parameters: '?9751

Creates a zip file with the given files

Parameters

  • workingDir - The relative dir of the zip files. Use this parameter to influence directory structure within zip file.
  • fileName - The fileName of the resulting zip file.
  • comment - A comment for the resulting zip file.
  • level - The compression level.
  • flatten - If set to true then all subfolders are merged into the root folder.
  • files - A sequence with files to zip.
createZipOfIncludes(...)
Signature: fileName:string -> comment:'?9765 -> level:int -> files:seq<string * IGlobbingPattern> -> unit
Type parameters: '?9765

Creates a zip file with the given files.

Parameters

  • fileName - The file name of the resulting zip file.
  • comment - A comment for the resulting zip file.
  • level - The compression level.
  • files - A sequence of target folders and files to include relative to their base directory.
createZipSpec(...)
Signature: fileName:string -> comment:'?9754 -> level:int -> items:seq<string * string> -> unit
Type parameters: '?9754

Creates a zip file with the given files and specs.

Parameters

  • fileName - The fileName of the resulting zip file.
  • comment - A comment for the resulting zip file.
  • level - The compression level.
  • items - A sequence with files and their target location in the zip.
DefaultZipLevel
Signature: int

The default zip level

filesAsSpecs(workingDir files)
Signature: workingDir:string -> files:IGlobbingPattern -> seq<string * string>

This helper helps with creating complex zip file with multiple include patterns. This method will convert a given glob pattern with the given workingDir to a sequence of zip specifications.

Parameters

  • workingDir - The relative dir of the zip files. Use this parameter to influence directory structure within zip file.
  • files - A sequence of target folders and files to include relative to their base directory.

Sample

The following sample creates a zip file containing the files from multiple patterns and moves them to different folders within the zip file.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
Target "Zip" (fun _ ->
    [   !! "ci/build/project1/**/*"
            |> Zip.filesAsSpecs "ci/build/project1"
            |> Zip.moveToFolder "project1"
        !! "ci/build/project2/**/*"
            |> Zip.filesAsSpecs "ci/build/project2"
            |> Zip.moveToFolder "project2"
        !! "ci/build/project3/sub/dir/**/*"
            |> Zip.filesAsSpecs "ci/build/project3"
            |> Zip.moveToFolder "project3"
    ]
    |> Seq.concat
    |> Zip.zipSpec (sprintf @"ci/deploy/project.%s.zip" buildVersion) "" Zip.DefaultZipLevel
)
module Seq

from Microsoft.FSharp.Collections
val concat : sources:seq<#seq<'T>> -> seq<'T>
val sprintf : format:Printf.StringFormat<'T> -> 'T
filesAsSpecsFlatten(files)
Signature: files:IGlobbingPattern -> seq<string * string>

This helper helps with creating complex zip file with multiple include patterns.

Parameters

  • workingDir - The relative dir of the zip files. Use this parameter to influence directory structure within zip file.
  • files - A sequence of target folders and files to include relative to their base directory.

Sample

The following sample creates a zip file containing the files from multiple patterns and moves them to different folders within the zip file.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
Target "Zip" (fun _ ->
    [   !! "ci/build/project1/**/*"
            |> Zip.filesAsSpecsFlatten
            |> Zip.moveToFolder "project1"
        !! "ci/build/project2/**/*"
            |> Zip.filesAsSpecsFlatten
            |> Zip.moveToFolder "project2"
        !! "ci/build/project3/sub/dir/**/*"
            |> Zip.filesAsSpecs "ci/build/project3"
            |> Zip.moveToFolder "project3"
    ]
    |> Seq.concat
    |> Zip.zipSpec (sprintf @"ci/deploy/project.%s.zip" buildVersion)
)
module Seq

from Microsoft.FSharp.Collections
val concat : sources:seq<#seq<'T>> -> seq<'T>
val sprintf : format:Printf.StringFormat<'T> -> 'T
moveToFolder(path items)
Signature: path:string -> items:seq<string * string> -> seq<string * string>

This helper helps with creating complex zip file with multiple include patterns. This function will move a given list of zip specifications to the given folder (while keeping original folder structure intact).

Parameters

  • workingDir - The relative dir of the zip files. Use this parameter to influence directory structure within zip file.
  • files - A sequence of target folders and files to include relative to their base directory.

Sample

The following sample creates a zip file containing the files from multiple patterns and moves them to different folders within the zip file.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
Target "Zip" (fun _ ->
    [   !! "ci/build/project1/**/*"
            |> Zip.filesAsSpecsFlatten
            |> Zip.moveToFolder "project1"
        !! "ci/build/project2/**/*"
            |> Zip.filesAsSpecsFlatten
            |> Zip.moveToFolder "project2"
        !! "ci/build/project3/sub/dir/**/*"
            |> Zip.filesAsSpecs "ci/build/project3"
            |> Zip.moveToFolder "project3"
    ]
    |> Seq.concat
    |> Zip.zipSpec (sprintf @"ci/deploy/project.%s.zip" buildVersion)
)
module Seq

from Microsoft.FSharp.Collections
val concat : sources:seq<#seq<'T>> -> seq<'T>
val sprintf : format:Printf.StringFormat<'T> -> 'T
unzip(target fileName)
Signature: target:string -> fileName:string -> unit

Unzips a file with the given file name.

Parameters

  • target - The target directory.
  • fileName - The file name of the zip file.
unzipFirstMatchingFileInMemory(...)
Signature: predicate:(ZipArchiveEntry -> bool) -> zipFileName:string -> string

Unzips a single file from the archive with the given file name.

Parameters

  • predicate - The predictae for the searched file in the archive.
  • zipFileName - The file name of the zip file.
unzipSingleFileInMemory(...)
Signature: fileToUnzip:string -> zipFileName:string -> string

Unzips a single file from the archive with the given file name.

Parameters

  • fileToUnzip - The file inside the archive.
  • zipFileName - The file name of the zip file.
zip(workingDir fileName files)
Signature: workingDir:string -> fileName:string -> files:seq<string> -> unit

Creates a zip file with the given files.

Parameters

  • workingDir - The relative dir of the zip files. Use this parameter to influence directory structure within zip file.
  • fileName - The file name of the resulting zip file.
  • files - A sequence with files to zip.
zipFile(fileName targetFileName)
Signature: fileName:string -> targetFileName:string -> unit

Creates a zip file with the given file.

Parameters

  • fileName - The file name of the resulting zip file.
  • targetFileName - The file to zip.
zipOfIncludes(fileName files)
Signature: fileName:string -> files:seq<string * IGlobbingPattern> -> unit

Creates a zip file with the given files.

Parameters

  • fileName - The file name of the resulting zip file.
  • files - A sequence of target folders and files to include relative to their base directory.

Sample

The following sample creates a zip file containing the files from the two target folders and FileIncludes.

  • The files from the first FileInclude will be placed in the root of the zip file.
  • The files from the second FileInclude will be placed under the directory app_data\jobs\continuous\MyWebJob in the zip file.
 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
Target "Zip" (fun _ ->
    [   "", !! "MyWebApp/*.html"
            ++ "MyWebApp/bin/**/*.dll"
            ++ "MyWebApp/bin/**/*.pdb"
            ++ "MyWebApp/fonts/**"
            ++ "MyWebApp/img/**"
            ++ "MyWebApp/js/**"
            -- "MyWebApp/js/_references.js"
            ++ "MyWebApp/web.config"
        @"app_data\jobs\continuous\MyWebJob", !! "MyWebJob/bin/Release/*.*"
    ]
    |> Zip.zipOfIncludes (sprintf @"bin\MyWebApp.%s.zip" buildVersion)
)
val sprintf : format:Printf.StringFormat<'T> -> 'T
zipSpec(fileName items)
Signature: fileName:string -> items:seq<string * string> -> unit

Creates a zip file with the given files and specs.

Parameters

  • fileName - The fileName of the resulting zip file.
  • comment - A comment for the resulting zip file.
  • level - The compression level.
  • items - A sequence with files and their target location in the zip.