Output content of object from stored file or readable input

 @return [String] string-encoded copy of binary data
199052
def data
      @grid_file ||= self.class.grid.get(id) if persisted?
      return @grid_file.data if @grid_file

      file.rewind if file.respond_to? :rewind
      file.read
    end
10344
def encode_contents(self):
        

        header = struct.pack("<LL", self.offset, len(self.raw_data))
        return bytearray(header) + self.raw_data
1038135
def contents(path = nil)
      contents = []

      object = find_object(path || '/')
      contents << path unless path.nil? || object.nil?
      if object.is_a? Grit::Tree
        (object.blobs + object.trees).each do |obj|
          contents += contents(path.nil? ? obj.basename : File.join(path, obj.basename))
        end
      end

      contents
    end
1150718
def output_mapping
      @output_mapping ||= (
        hash = {}
        case output
        when Array
          output.each do |path|
            hash[path] = format(path)
          end
        when String
          hash[output] = format(output)
        when Hash
          hash = output
        end
        hash
      )
    end
691504
def to_output_hash
      HASH_SCHEMA.schema(
        map { |attr| [attr.key, attr.to_read_type] }.to_h
      )
    end
1281891
def readme
      file = File.readlines(File.join(File.dirname(__FILE__), "README"))
      file.each { |f| @output.print f }
    end
489033
def pdf_from_string(string, output_file = '-')
      with_timeout do
        pdf = initialize_pdf_from_string(string, output_file, {:output_to_log_file => false})
        pdf.close_write
        result = pdf.gets(nil)
        pdf.close_read
        result.force_encoding('BINARY') if RUBY_VERSION >= "1.9"

        result
      end
    end
1225686
def dumps_content(self):
        

        import numpy as np

        string = ''
        shape = self.matrix.shape

        for (y, x), value in np.ndenumerate(self.matrix):
            if x:
                string += '&'
            string += str(value)

            if x == shape[1] - 1 and y != shape[0] - 1:
                string += r'\\' + '%\n'

        super().dumps_content()

        return string
598177
def get_contents_from_files *files
        return files.flatten.map do |filename|
          file    = Pathname.new filename
          content = file.read
          path    = remove_storage_path_from file.to_path
          next [path, content]
        end .to_h
      end
704696
def _get_log_file_data_as_encoded_content():
    
    with io.BytesIO() as fp:
        with tarfile.open(fileobj=fp, mode='w:gz') as tar:
            for f in OUTPUT_FILES:
                if os.path.isfile(f):
                    tar.add(f)

        fp.seek(0)
        return base64.encode_as_bytes(fp.getvalue())
164344
def encoded_contents(asset_path)
      return @asset_contents[asset_path] if @asset_contents[asset_path]
      data = read_binary_file(asset_path)
      @asset_contents[asset_path] = Base64.encode64(data).gsub(/\n/, '')
    end
895921
def template_content
      if File.file?(@template_file) && File.readable?(@template_file)
        return File.read(@template_file)
      end

      raise ArgumentError, _("'%{template}' is not a readable file") % { template: @template_file }
    end
606881
def prepare

      # if output_dir is not specified, output in the same directory
      # as the imput file
      if !@output_dir && @input_file
        @output_dir = File.dirname(@input_file)
      end

      # if input file is bz2 compressed, use bz2-ruby if available,
      # use command line bzip2 program otherwise.
      if /.bz2$/ =~ @input_file
        unless NO_BZ2
          file = Bzip2::Reader.new File.open(@input_file, "r:UTF-8")
          @parent.msg("WP2TXT is spawming #{@num_threads} threads to process data \n", 0)         
          @parent.msg("Preparing ... This may take several minutes or more ", 0)         
          @infile_size = file_size(file)
          @parent.msg("... Done.", 1)
          file.close
          file = Bzip2::Reader.new File.open(@input_file, "r:UTF-8")
        else
          if RUBY_PLATFORM.index("win32")
            file = IO.popen("bunzip2.exe -c #{@input_file}")
          else
            file = IO.popen("bzip2 -c -d #{@input_file}") 
          end
          @parent.msg("WP2TXT is spawming #{@num_threads} threads to process data \n", 0)         
          @parent.msg("Preparing ... This may take several minutes or more ", 0)         
          @infile_size = file_size(file)
          @parent.msg("... Done.", 1)
          file.close  # try to reopen since rewind method is unavailable
          if RUBY_PLATFORM.index("win32")
            file = IO.popen("bunzip2.exe -c #{@input_file}")
          else
            file = IO.popen("bzip2 -c -d #{@input_file}") 
          end
        end 
      else # meaning that it is a text file
        @infile_size = File.stat(@input_file).size
        file = open(@input_file)
      end

      #create basename of output file
      @outfile_base = File.basename(@input_file, ".*") + "-"            
      @total_size = 0
      @file_index = 1
      outfilename = File.join(@output_dir, @outfile_base + @file_index.to_s)
      @outfiles = []
      @outfiles << outfilename
      @fp = File.open(outfilename, "w")    
      @parent.before
      @parent.data_set(@input_file, 100 * 100)
      @file_pointer = file
      return true
    end
1038945
function () {
    var chunks = [];
    return through2.obj(function (file, enc, cb) {
        chunks.push(file);
        var string = file._contents.toString();
        var regex  = /\/\*\*debug:start\*\*\/[\s\S]*\/\*\*debug:end\*\*\//g;
        var stripped = string.replace(regex, "");
        file.contents = new Buffer(stripped);
        this.push(file);
        cb();
    });
}
1310683
def write_to_string
      string_io = StringIO.new.set_encoding(Encoding::BINARY)
      write_to_string_io(string_io)
      string_io.string
    end
131889
def content
      return unless present?
      @content ||= YAML.load(File.open(path))
    rescue Psych::SyntaxError => e
      # Using $stdout.puts so that it can be stubbed out on jruby.
      $stdout.puts "Your Cloudfile has invalid YAML syntax."
      $stdout.puts "You are seeing this message because we stopped supporting invalid YAML that was allowed in Ruby 1.8."
      $stdout.puts ""
      $stdout.puts "The most likely reason is a string starting with '*' in the domains array. The solution is to surround such strings with quotes, e.g.:"
      $stdout.puts "domains:"
      $stdout.puts "  - \"*.example.com\""
      $stdout.puts ""
      $stdout.puts "The original YAML error message was:"
      $stdout.puts "  #{e.message}"
      $stdout.puts ""
      $stdout.puts "If you need any assistance, feel free to contact support@shellycloud.com"
      exit 1
    end
363229
def parse!
      unless File.exists? output_file_path
        @status = 'error'
        @error = ContainerError.new('User code did not finish properly')
        @error_to_raise = @error
        return
      end

      begin
        data = File.binread output_file_path
        @raw_response = Marshal.load(data)
      rescue => e
        @status = 'error'
        @error = e
        @error_to_raise = ContainerError.new(e)
        return
      end

      unless ['success', 'error'].include? @raw_response[:status]
        @status = 'error'
        @error = InternalError.new('Output file has invalid format')
        @error_to_raise = @error
        return
      end

      @status = @raw_response[:status]
      @output = @raw_response[:output]
      @error = @raw_response[:error]
      @error_to_raise = UserCodeError.new(@error) if @error
      nil
    end