Class: CIFS::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/jcifs.rb

Overview

This class reads SmbFiles

Direct Known Subclasses

RangeFileReader

Instance Method Summary (collapse)

Constructor Details

- (FileReader) initialize(smbfile)



78
79
80
81
82
# File 'lib/jcifs.rb', line 78

def initialize(smbfile)
    @smbfile = smbfile
    @bytes = Java::byte[128 * 1024].new
    self.create_input
end

Instance Method Details

- (Object) each

This yields chunks of the body, rack calls this to generate the request body



103
104
105
106
107
# File 'lib/jcifs.rb', line 103

def each # :yields: bodychunk
    while ( read = @input.read(@bytes) ) > 0
        yield String.from_java_bytes(@bytes[Range.new(0, read-1)])
    end
end

- (Object) mime_type

returns the mime type of the SmbFile based on it's file name



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/jcifs.rb', line 89

def mime_type
    name = @smbfile.getName
    mime = MIME::Types.type_for(name)[0]

    if ['text/plain'].find_index(mime)
        return mime.to_s + "; charset=utf-8"
    end

    return mime.to_s if mime
    return 'application/octet-stream'
end