RSDFileResultUtility

public class RSDFileResultUtility

RSDFileResultUtility is a utility for naming temporary files used to save task results.

  • This utility will create a filename scrubbing the identifier string of any characters that are not alpha-numeric, dash, or underscore characters. Additionally, this utility will replace ‘.’ and whitespace characters with an underscore. Finally, the string will be shortened (if needed) to 24 characters. If the resulting string is empty then a UUID will be created and this will be used as the name of the file.

    Declaration

    Swift

    public static func filename(for identifier: String) -> String

    Parameters

    identifier

    The string to use to create the file name.

    Return Value

    The scrubbed string.

  • Convenience method for creating a file URL to use as the location to save data.

    This utility will first create the output directory if needed. Then it will append the scrubbed filename using the filename() utility function. Finally, the url will be checked and if the file already exists, then the filename will be appended with a random 4-letter UUID code.

    The purpose of using this method is two-fold. First, it uses a directory that is simplier for developers to find while developing a recorder. Second, it limits the length of the file path components to avoid issues with length limits in the stored filename if the name is stored to a database.

    Throws

    An exception if the file directory cannot be created.

    Declaration

    Swift

    public static func createFileURL(identifier: String, ext: String, outputDirectory: URL, shouldDeletePrevious: Bool = false) throws -> URL

    Parameters

    identifier

    The identifier string for the step or configuration that will use the file.

    ext

    The file extension.

    outputDirectory

    File URL for the directory in which to store generated data files.

    Return Value

    Scrubbed URL for the given identifier.