public async Task PushPackage(PackageDefinition packageDefinition, Stream packageStream)
        {
            if (string.IsNullOrEmpty(_writeToken))
            {
                throw new Exception("Please provide an access token to be used during package push.");
            }

            packageStream.Position = 0;

            string data = null;

            using (var streamCopy = (MemoryStream)await StreamUtilities.MakeMemoryCopy(packageStream))
            {
                data = Convert.ToBase64String(streamCopy.ToArray());
            }


            var uploadJson = new JObject();

            uploadJson.Add(new JProperty("_id", packageDefinition.PackageIdentifier + "@" + packageDefinition.PackageVersion));
            uploadJson.Add(new JProperty("name", packageDefinition.PackageIdentifier));
            uploadJson.Add(new JProperty("version", packageDefinition.PackageVersion));
            uploadJson.Add(new JProperty("dist", new JObject(
                                             new JProperty("shasum", ""),
                                             new JProperty("tarball", $"{_repositoryUrl}/{packageDefinition.PackageIdentifier}/-/{packageDefinition.PackageIdentifier}-{packageDefinition.PackageVersion}.tgz"))));

            uploadJson.Add(new JProperty("_attachments", new JObject(
                                             new JProperty(packageDefinition.PackageIdentifier + "-" + packageDefinition.PackageVersion + ".tgz", new JObject(
                                                               new JProperty("content_type", "application/octet-stream"),
                                                               new JProperty("data", data),
                                                               new JProperty("length", data.Length)
                                                               )))));

            //uploadJson.Merge(npmPackage.PackageJson);

            var content = new StringContent(uploadJson.ToString());

            var request = new HttpRequestMessage(HttpMethod.Put, _repositoryUrl + "/" + packageDefinition.PackageIdentifier);

            request.Headers.Add("X-NuGet-ApiKey", _writeToken);
            request.Content = content;

            var response = await HttpClient.SendAsync(request);

            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception ex)
            {
                Log.Logger.Error("Error pushing {packageType} package {packageIdentifier}@{packageVersion}. Status: {statusCode} - {statusReason}.",
                                 packageDefinition.PackageType, packageDefinition.PackageIdentifier, packageDefinition.PackageVersion,
                                 response.StatusCode, response.ReasonPhrase, ex);
            }
        }
        private async Task <HttpResponseMessage> PushPackageAsRequestBodyAsync(string accessToken, Stream packageStream, TimeSpan timeout, HttpMethod httpMethod)
        {
            // NOTE: For some reason, Microsoft decided StreamContent should dispose the stream, so work with a copy as we do not want to dispose here.
            using (var streamCopy = await StreamUtilities.MakeMemoryCopy(packageStream))
            {
                var content = new StreamContent(streamCopy);

                var request = new HttpRequestMessage(httpMethod, _repositoryUrl + "/package");
                request.Headers.Add("X-NuGet-ApiKey", accessToken);
                request.Content = content;

                return(await HttpClient.SendAsync(request));
            }
        }