Class: CmisServer::ContentStream

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, base64: nil, media_type: nil, filename: nil) ⇒ ContentStream

Returns a new instance of ContentStream.



13
14
15
16
17
18
# File 'lib/cmis_server/content_stream.rb', line 13

def initialize(id: nil, base64: nil, media_type: nil, filename: nil)
  @media_type=media_type
  @base64    =base64
  @id        =id
  @filename  =filename
end

Instance Attribute Details

#base64Object

Returns the value of attribute base64.



9
10
11
# File 'lib/cmis_server/content_stream.rb', line 9

def base64
  @base64
end

#filenameObject

Returns the value of attribute filename.



10
11
12
# File 'lib/cmis_server/content_stream.rb', line 10

def filename
  @filename
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/cmis_server/content_stream.rb', line 11

def id
  @id
end

#media_typeObject

Returns the value of attribute media_type.



8
9
10
# File 'lib/cmis_server/content_stream.rb', line 8

def media_type
  @media_type
end

Instance Method Details

#contentObject



28
29
30
# File 'lib/cmis_server/content_stream.rb', line 28

def content
  Base64.decode64(self.base64)
end

#default_extensionsObject



24
25
26
# File 'lib/cmis_server/content_stream.rb', line 24

def default_extensions
  MIME::Types[self.media_type].first&.extensions&.first||'txt'
end

#lengthObject



20
21
22
# File 'lib/cmis_server/content_stream.rb', line 20

def length
  content.bytesize
end

#tempfile(name = 'tempfile') ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/cmis_server/content_stream.rb', line 32

def tempfile(name='tempfile')
  t=Tempfile.new([name, ".#{default_extensions}"])
  t.binmode
  t.write(self.content)
  t.close
  t.open
  t
end

#with_tempfile(&block) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/cmis_server/content_stream.rb', line 41

def with_tempfile(&block)
  temp_file=self.tempfile
  begin
    block.call(temp_file)
  ensure
    temp_file.close
    temp_file.unlink
  end
end