Downloads the file to a Tempfile on disk and returns this tempfile.

 @example
   file = backend.upload(StringIO.new("hello"))
   tempfile = file.download
   File.read(tempfile.path) # => "hello"

 @return [Tempfile] a tempfile with the file's content
761263
def download
      return io if io.is_a?(Tempfile)

      Tempfile.new(id, binmode: true).tap do |tempfile|
        IO.copy_stream(io, tempfile)
        tempfile.rewind
        tempfile.fsync
      end
    end
1143851
def with_temp_dir(dir=nil)
      dir ||= Dir.mktmpdir(TEMP_PREFIX, @temp_root)
      dir = Pathname.new(dir)

      yield dir
    ensure
      FileUtils.rm_rf(dir.to_s)
    end
1269302
def write_and_get_hash(path, write_to_file, hash=None):
    
    hash = hash or hashlib.md5()
    try:
        # Access path
        r = config.DOWNLOAD_SESSION.get(path, stream=True)
        r.raise_for_status()
        for chunk in r:
            write_to_file.write(chunk)
            hash.update(chunk)

    except (MissingSchema, InvalidSchema):
        # If path is a local file path, try to open the file (generate hash if none provided)
        with open(path, 'rb') as fobj:
            for chunk in iter(lambda: fobj.read(2097152), b""):
                write_to_file.write(chunk)
                hash.update(chunk)

    assert write_to_file.tell() > 0, "File failed to write (corrupted)."

    return hash
371949
def get(self):
        
        if self.local_file.endswith('.whl'):
            self.temp_dir = tempfile.mkdtemp()
            save_dir = self.temp_dir
        else:
            save_dir = self.save_dir

        save_file = '{0}/{1}'.format(save_dir, os.path.basename(
            self.local_file))
        if not os.path.exists(save_file) or not os.path.samefile(
                self.local_file, save_file):
            shutil.copy2(self.local_file, save_file)
        logger.info('Local file: {0} copyed to {1}.'.format(
            self.local_file, save_file))

        return save_file
981088
def file(options = {})
      options[:file_name] ||= 'pass.mswallet'
      temp_file = Tempfile.new(options[:file_name])
      temp_file.write self.stream.string
      temp_file.close
      temp_file
    end
443385
def raw_data
      return IO.read(@on_disk_path) if on_disk?
      return nil unless @blob

      if !@wiki.repo.bare && @blob.is_symlink
        new_path = @blob.symlink_target(::File.join(@wiki.repo.path, '..', self.path))
        return IO.read(new_path) if new_path
      end

      @blob.data
    end
858155
def download_and_transform_file(self, path):
        
        key = "DOWNLOAD:{}".format(path)
        if not config.UPDATE and FILECACHE.get(key):
            return FILECACHE.get(key).decode('utf-8')

        config.LOGGER.info("\tDownloading {}".format(path))

        # Write file to temporary file
        if self.subtitlesformat == file_formats.VTT:
            with tempfile.TemporaryFile() as tempf:
                hash = write_and_get_hash(path, tempf)
                tempf.seek(0)

                # Get extension of file or default if none found
                filename = '{0}.{ext}'.format(hash.hexdigest(), ext=self.default_ext)
                copy_file_to_storage(filename, tempf)
                FILECACHE.set(key, bytes(filename, "utf-8"))
        elif self.subtitlesformat == file_formats.SRT:
            with tempfile.NamedTemporaryFile() as tempf_srt,\
                tempfile.NamedTemporaryFile() as tempf_vtt:
                hash_srt = write_and_get_hash(path, tempf_srt)
                tempf_srt.seek(0)
                filename_tmp_vtt = os.path.join(
                    "/tmp", '{0}.{ext}'.format(hash_srt.hexdigest(), ext=self.default_ext))
                error_msg = srt2vtt(tempf_srt.name, filename_tmp_vtt)
                
                hash = write_and_get_hash(filename_tmp_vtt, tempf_vtt)
                tempf_vtt.seek(0)
                
                filename = '{0}.{ext}'.format(hash.hexdigest(), ext=self.default_ext)
                copy_file_to_storage(filename, tempf_vtt.name)
                if error_msg is not None:
                    config.LOGGER.error(" An Error found in " + path)
                    config.LOGGER.error(error_msg)
                else:
                    FILECACHE.set(key, bytes(filename, "utf-8"))
        return filename
867849
private static function getTemporaryFile() {
        if(is_callable(self::$temp)) {
            $temporaryFile = @call_user_func(self::$temp);
            if(is_string($temporaryFile) && strlen($temporaryFile) && is_writable($temporaryFile)) {
                return $temporaryFile;
            }
        }
        $temporaryDirectory = (is_string(self::$temp) && strlen(self::$temp)) ? self::$temp : sys_get_temp_dir();
        return tempnam($temporaryDirectory, 'Zip');
    }
434203
def download(spec, target = nil)
      if target.nil?
        ext = File.extname(spec['file_name'])
        base = File.basename(spec['file_name'], ext)
        target = Dir::Tmpname.create([base, ext]) {}
      end

      File.open(target, 'wb') do |output|
        retrieve(spec) do |chunk, retrieved, total|
          output.write(chunk)
          yield(target, retrieved, total) if block_given?
        end
      end
      target
    end
494918
def write(temp_object, opts={})
      temp_object.file do |fd|
        File.new.tap do |file|
          file.metadata = temp_object.meta
          file.data     = fd
          file.save!
          return file.id.to_s
        end
      end
    end
471844
def createTempFile(self, suffix=None, prefix=None, secure=True) -> 'File':
        
        if not secure:
            raise NotImplementedError("We only support secure files at this point")

        # tempfile.mkstemp(suffix=None, prefix=None, dir=None, text=False)

        newFileNum, newFileRealPath = tempfile.mkstemp(
            suffix=suffix, prefix=prefix, dir=self._path)
        os.close(newFileNum)

        relativePath = os.path.relpath(newFileRealPath, self.path)

        file = File(self, pathName=relativePath, exists=True)
        self._files[file.pathName] = file
        return file
52485
def download(parent_path=nil)
      file = Pathname('.').join((parent_path || album_name), url.split('/').last)
      @downloader = Downloader.new(url, file)
      @downloader.download
    end
1142439
def download_from_source(file)
      source_host = Gemirro.configuration.source.host
      Utils.logger.info("Download from source: #{file}")
      resp = Http.get("#{source_host}/#{File.basename(file)}")
      return unless resp.code == 200
      resp.body
    end
1229226
def touch(filename)
      unless in_zip?
        FileUtils.touch current_dir.join(filename)
      else
        Zip::File.open(current_zip) do |zip|
          # zip.file.open(filename, 'w') {|_f| }  #HAXX this code creates an unneeded temporary file
          zip.instance_variable_get(:@entry_set) << Zip::Entry.new(current_zip, filename)
        end
      end
      ls
    end
221902
public static File getTempDir() {
        final String str = System.getProperty(TEMP_DIR_KEY);
        if (str == null) {
            throw new IllegalStateException("System property '" + TEMP_DIR_KEY + "' not found!");
        }
        final String tempDirStr = str.trim();
        if (tempDirStr.length() == 0) {
            throw new IllegalStateException("System property '" + TEMP_DIR_KEY + "' is empty!");
        }
        final File dir = new File(tempDirStr);
        try {
            checkValidDir(dir);
        } catch (final IllegalArgumentException ex) {
            throw new IllegalStateException("System property '" + TEMP_DIR_KEY + "' is not valid! [" + ex.getMessage() + "]");
        }
        return dir;
    }
252255
def download_file(url, path=None, clobber=False):
    
    if path is None:
        local_filename = os.path.join(directory, url.split('/')[-1])
    else:
        local_filename = path

    if os.path.exists(local_filename) and not clobber:
        logging.info('{} exists; not downloading.'.format(local_filename))
        return local_filename
        
    # NOTE the stream=True parameter
    r = requests.get(url, stream=True)
    with open(local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)
                #f.flush() commented by recommendation from J.F.Sebastian
    return local_filename
480578
def download!
      return download if file.nil?

      file.close
      file.unlink
      self.file = nil
      download
    end