cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-9839) Add gzip support to file-transfer.download on wp8
Date Tue, 21 Nov 2017 22:28:00 GMT

    [ https://issues.apache.org/jira/browse/CB-9839?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16261593#comment-16261593
] 

ASF GitHub Bot commented on CB-9839:
------------------------------------

maverickmishra closed pull request #85: CB-9839 Add gzip support to file-transfer.download
on wp8
URL: https://github.com/apache/cordova-plugin-file-transfer/pull/85
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/plugin.xml b/plugin.xml
index f2c39ed..2d9d381 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -134,7 +134,8 @@
         </config-file>
 
         <source-file src="src/wp/FileTransfer.cs" />
-
+      
+        <framework src="src/wp/System.IO.Compression.dll" custom="true" />
     </platform>
 
     <!-- windows8 -->
diff --git a/src/wp/FileTransfer.cs b/src/wp/FileTransfer.cs
index 675690f..d280282 100644
--- a/src/wp/FileTransfer.cs
+++ b/src/wp/FileTransfer.cs
@@ -25,6 +25,7 @@
 using System.Diagnostics;
 using System.Threading.Tasks;
 using WPCordovaClassLib.Cordova.JSON;
+using System.IO.Compression;
 
 namespace WPCordovaClassLib.Cordova.Commands
 {
@@ -88,7 +89,7 @@ public TransferOptions()
         public const int ConnectionError = 3;
         public const int AbortError = 4; // not really an error, but whatevs
 
-        private static Dictionary<string, DownloadRequestState> InProcDownloads = new
Dictionary<string,DownloadRequestState>();
+        private static Dictionary<string, DownloadRequestState> InProcDownloads = new
Dictionary<string, DownloadRequestState>();
 
         // Private instance of the main WebBrowser instance
         // NOTE: Any access to this object needs to occur on the UI thread via the Dispatcher
@@ -236,7 +237,7 @@ protected struct Header
         public FileTransfer()
         {
             // look for Newtonsoft.Json availability
-            foreach(System.Reflection.Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()
)
+            foreach (System.Reflection.Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
             {
                 if (assembly.GetType("Newtonsoft.Json.ConstructorHandling") != null)
                 {
@@ -356,7 +357,7 @@ public FileTransfer()
                     uploadOptions.Params = args[5];
 
                     bool trustAll = false;
-                    bool.TryParse(args[6],out trustAll);
+                    bool.TryParse(args[6], out trustAll);
                     uploadOptions.TrustAllHosts = trustAll;
 
                     bool doChunked = false;
@@ -418,18 +419,18 @@ public FileTransfer()
             }
             catch (Exception /*ex*/)
             {
-                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new FileTransferError(ConnectionError)),callbackId);
+                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new FileTransferError(ConnectionError)),
callbackId);
             }
         }
 
         // example : "{\"Authorization\":\"Basic Y29yZG92YV91c2VyOmNvcmRvdmFfcGFzc3dvcmQ=\"}"
-        protected Dictionary<string,string> parseHeaders(string jsonHeaders)
+        protected Dictionary<string, string> parseHeaders(string jsonHeaders)
         {
             try
             {
                 if (FileTransfer.HasJsonDotNet)
                 {
-                    return JsonHelper.Deserialize<Header[]>(jsonHeaders,true)
+                    return JsonHelper.Deserialize<Header[]>(jsonHeaders)
                         .ToDictionary(header => header.Name, header => header.Value);
                 }
                 else
@@ -461,7 +462,7 @@ public FileTransfer()
                 downloadOptions.FilePath = optionStrings[1];
 
                 bool trustAll = false;
-                bool.TryParse(optionStrings[2],out trustAll);
+                bool.TryParse(optionStrings[2], out trustAll);
                 downloadOptions.TrustAllHosts = trustAll;
 
                 downloadOptions.Id = optionStrings[3];
@@ -481,7 +482,7 @@ public FileTransfer()
                 {
                     using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                     {
-                        string cleanUrl = downloadOptions.Url.Replace("x-wmapp0:", "").Replace("file:",
"").Replace("//","");
+                        string cleanUrl = downloadOptions.Url.Replace("x-wmapp0:", "").Replace("file:",
"").Replace("//", "");
 
                         // pre-emptively create any directories in the FilePath that do not
exist
                         string directoryName = getDirectoryName(downloadOptions.FilePath);
@@ -697,31 +698,48 @@ private void downloadCallback(IAsyncResult asynchronousResult)
                     {
                         long totalBytes = response.ContentLength;
                         int bytesRead = 0;
-                        using (BinaryReader reader = new BinaryReader(response.GetResponseStream()))
+
+                        string encodingHeader = response.Headers["Content-Encoding"] != null
? response.Headers["Content-Encoding"] : "";
+                        
+                        bool useGzip = encodingHeader.Contains("gzip");
+                        using (Stream responseStreamGz = useGzip ? new GZipStream(response.GetResponseStream(),
CompressionMode.Decompress) : response.GetResponseStream())
                         {
-                            using (BinaryWriter writer = new BinaryWriter(fileStream))
-                            {
-                                int BUFFER_SIZE = 1024;
-                                byte[] buffer;
 
-                                while (true)
+                            using (BinaryReader reader = new BinaryReader(responseStreamGz))
+                            {
+                                using (BinaryWriter writer = new BinaryWriter(fileStream))
                                 {
-                                    buffer = reader.ReadBytes(BUFFER_SIZE);
-                                    // fire a progress event ?
-                                    bytesRead += buffer.Length;
-                                    if (buffer.Length > 0 && !reqState.isCancelled)
-                                    {
-                                        writer.Write(buffer);
-                                        DispatchFileTransferProgress(bytesRead, totalBytes,
callbackId);
-                                    }
-                                    else
+                                    int BUFFER_SIZE = 1024;
+                                    byte[] buffer;
+
+                                    while (true)
                                     {
-                                        writer.Close();
-                                        reader.Close();
-                                        fileStream.Close();
-                                        break;
+                                        buffer = reader.ReadBytes(BUFFER_SIZE);
+                                        // fire a progress event ?
+                                        bytesRead += buffer.Length;
+                                        
+                                        if (buffer.Length > 0 && !reqState.isCancelled)
+					{
+					    writer.Write(buffer);
+					
+					    if (useGzip)
+					    {
+					        DispatchFileTransferProgress(0, 0, callbackId);
+					    }
+					    else
+					    {
+					        DispatchFileTransferProgress(bytesRead, totalBytes, callbackId);
+					    }
+					}
+                                        else
+                                        {
+                                            writer.Close();
+                                            reader.Close();
+                                            fileStream.Close();
+                                            break;
+                                        }
+                                        System.Threading.Thread.Sleep(1);
                                     }
-                                    System.Threading.Thread.Sleep(1);
                                 }
                             }
                         }
diff --git a/src/wp/System.IO.Compression.dll b/src/wp/System.IO.Compression.dll
new file mode 100644
index 0000000..1764379
Binary files /dev/null and b/src/wp/System.IO.Compression.dll differ


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Add gzip support to file-transfer.download on wp8
> -------------------------------------------------
>
>                 Key: CB-9839
>                 URL: https://issues.apache.org/jira/browse/CB-9839
>             Project: Apache Cordova
>          Issue Type: New Feature
>          Components: cordova-plugin-file-transfer
>            Reporter: Sergey Shakhnazarov
>              Labels: gzip, wp8
>




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message