Note: This is the migration API reference for FAKE 5. The new (modularized) API documentation can be found here. If the API is already migrated you can check here if exists in a module. More information regarding the migration can be found here

Zip

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

Functions and values

Function or valueDescription
Zip.createZip(...)
Signature: workingDir:string -> fileName:string -> comment:string -> level:int -> flatten:bool -> 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 fileName of the resulting zip file.
  • comment - A comment for the resulting zip file (currently ignored in fake 5).
  • 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.
Zip.createZipOfIncludes(...)
Signature: fileName:string -> comment:string -> level:int -> files:seq<string * IGlobbingPattern> -> unit

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 (currently ignored in fake 5).
  • level - The compression level.
  • files - A sequence of target folders and files to include relative to their base directory.
Zip.createZipSpec(...)
Signature: fileName:string -> comment:string -> level:int -> 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 (currently ignored in fake 5).
  • level - The compression level.
  • items - A sequence with files and their target location in the zip.
Zip.DefaultZipLevel
Signature: int

The default zip level

Zip.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)
)
module Seq

from Microsoft.FSharp.Collections
val concat : sources:seq<#seq<'T>> -> seq<'T>
val sprintf : format:Printf.StringFormat<'T> -> 'T
Zip.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
Zip.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
Zip.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.
Zip.unzipFirstMatchingFileInMemory(...)
Signature: predicate:(ZipEntry -> bool) -> zipFileName:string -> string

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

Parameters

  • predicate - The predicate for the searched file in the archive.
  • zipFileName - The file name of the zip file.
Zip.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.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.
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.
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
Zip.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.
  • items - A sequence with files and their target location in the zip.