S5TFUtils

public struct S5TFUtils

General helper functions for Swift.

  • Run a command in the shell.

    Usage Example:

    • Execute ls -l -g:
       shell("/bin/ls", "-l", "-g")
    
    • Execute ls -lah
       shell("/bin/ls", "-lah")
    

    Declaration

    Swift

    @discardableResult
    public static func shell(_ launchPath: String, _ arguments: String...) throws -> (out: String?, status: Int32)

    Return Value

    Output, termination status of the command.

  • Run a command in the shell.

    Wrapper for shell(_ launchPath: String, arguments: String...) because splatting is not supported in Swift. See https://bugs.swift.org/browse/SR-128 for more details.

    • Usage Example:

      • Execute ls -l -g:
      shell("/bin/ls", ["-l", "-g"])
      
      • Execute ls -lah
      shell("/bin/ls", ["-lah"])
      

    Declaration

    Swift

    @discardableResult
    public static func shell(_ launchPath: String, _ arguments: [String]) throws -> (out: String?, status: Int32)

    Return Value

    Output, termination status of the command.

  • Extract a downloaded archive

    Supported file extensions:

    • .gz
    • .tgz

    Usage Example:

    • Extract archive.tgz:
      extract(fileAt: URL(string: "archive.tgz")!)
    
    • Extract another_archive.gz
      extract(fileAt: URL(string: "archive_archive.gz")!)
    

    Declaration

    Swift

    public static func extract(archiveURL: URL) -> URL

    Return Value

    output, termination status of the command.

  • Download and extract an archive.

    Usage Example:

      downloadAndExtract(remoteURL: URL(string: "https://storage.googleapis.com/cvdf-datasets/mnist/train-images-idx3-ubyte.gz")!,
                         cacheName: "mnist", fileName: "train_images")
    

    Declaration

    Swift

    public static func downloadAndExtract(remoteURL: URL, cacheName: String, fileName: String) -> URL?

    Return Value

    URL of extracted archive.