// Save the new package file, creating a new version name for it
        public SavePackageResult SavePackageToLibrary(string appName, string componentName, Stream contents)
        {
            string libraryDirectoryPath = Path.Combine(_config.AppLibraryBasePath, appName, componentName);

            libraryDirectoryPath = FileSystem.FixPath(libraryDirectoryPath);
            if (!Directory.Exists(libraryDirectoryPath))
            {
                Directory.CreateDirectory(libraryDirectoryPath);
            }

            var existingVersions = Directory.EnumerateFiles(libraryDirectoryPath, "*.zip")
                                   .Select(Path.GetFileNameWithoutExtension);
            var nextVersion = _versions.GetNextAvailableVersion(existingVersions);

            string libraryFilePath = Path.Combine(libraryDirectoryPath, nextVersion + ".zip");

            using (var fileStream = File.Open(libraryFilePath, FileMode.Create, FileAccess.Write))
                contents.CopyTo(fileStream);

            return(new SavePackageResult
            {
                Version = nextVersion,
                FilePath = libraryFilePath
            });
        }