changeset 12588:3f24658504ab octave-forge

support ftp when curl is installed
author abarth93
date Thu, 09 Apr 2015 17:43:15 +0000
parents 75ddf8166364
children 06a805605e9a
files extra/ncArray/inst/cached_decompress.m
diffstat 1 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/extra/ncArray/inst/cached_decompress.m	Thu Apr 09 10:02:47 2015 +0000
+++ b/extra/ncArray/inst/cached_decompress.m	Thu Apr 09 17:43:15 2015 +0000
@@ -21,7 +21,7 @@
 global CACHED_DECOMPRESS_MAX_SIZE
 
 
-if beginswith(url,'http:') || ...
+if startswith(url,'http:') || ...
         ~(endswith(url,'.gz') || endswith(url,'.bz2') || endswith(url,'.xz'))
   % opendap url or not compressed file
   fname = url;
@@ -63,16 +63,26 @@
 
 if exist(fname,'file') ~= 2
     if endswith(url,'.gz')
-        syscmd('gunzip --stdout "%s" > "%s"',url,fname);
+      cmd = 'gunzip --stdout -';
     elseif endswith(url,'.bz2')
-        syscmd('bunzip2 --stdout "%s" > "%s"',url,fname);
+      cmd = 'bunzip2 --stdout -';
+    elseif endswith(url,'.xz')
+      cmd = 'unxz --stdout -';
     else
-        syscmd('unxz --stdout "%s" > "%s"',url,fname);
+      cmd = 'cat';
     end    
+
+    if startswith(url,'ftp://')
+      syscmd('curl --silent "%s" | %s > "%s"',url,cmd,fname);
+    else
+      syscmd('%s < "%s" > "%s"',cmd,url,fname);
+    end
 else
 %    fprintf(fid,'retrieve from cache %s\n',url);
 end
 
+
+
 % check cache size
 
 d=dir(cache_dir);
@@ -106,23 +116,23 @@
 end
 end
 
-function t = beginswith(s,pre)
+
+function t = startswith(s,ext)
 
-if length(pre) <= length(s)
-    t = strcmp(s(1:length(pre)),pre);
-else
+  if length(ext) <= length(s)
+    t = strcmp(s(1:length(ext)),ext);
+  else
     t = 0;
-end
+  end
 end
 
-
 function t = endswith(s,ext)
 
-if length(ext) <= length(s)
+  if length(ext) <= length(s)
     t = strcmp(s(end-length(ext)+1:end),ext);
-else
+  else
     t = 0;
-end
+  end
 end