Class: TaliaCore::DataTypes::FileRecord

Inherits:
DataRecord show all
Extended by:
DataLoader::ClassMethods, IipLoader, PathHelpers::ClassMethods, TaliaUtil::IoHelper
Includes:
DataLoader, FileStore, PathHelpers
Defined in:
lib/talia_core/data_types/file_record.rb

Overview

Base class for all data records that use a plain file for data storage. This implements the DataRecord API so that all byte methods work on a file in the File system.

Most of the operations are defined in the FileStore module, see there on how to create and work with file records.

See the DataLoader and MimeMapping modules to see new file records are created automatically, depending on the MIME type.

The data paths are set automatically by the class, see PathHelpers

There is also an IipLoader module, that contains the loader mechanism for creating Iip images - you can also use that as an example to create new loaders for other file types.

Direct Known Subclasses

IipData, ImageData, PdfData, SimpleText, XmlData

Instance Attribute Summary

Attributes inherited from DataRecord

#temp_path

Instance Method Summary collapse

Methods included from PathHelpers::ClassMethods

data_path, tempfile_path

Methods included from DataLoader::ClassMethods

create_from_url

Methods included from IipLoader

convert_original?, create_from_files, create_from_stream, create_iip, open_original_image, open_original_image_file, open_original_image_stream, orig_location, prepare_image_from_existing!

Methods included from TaliaUtil::IoHelper

base_for, file_url, open_from_url, open_generic

Methods included from PathHelpers

#data_directory, #data_path, #extract_filename, #file_path, #full_filename, #static_path, #tempfile_path

Methods included from FileStore

#all_text, #assign_type, #create_from_data, #create_from_file, #is_file_open?, #write_file_after_save

Methods inherited from DataRecord

#content_string, #extract_mime_type, find_by_type_and_location!, find_data_records, #mime_type

Instance Method Details

#all_bytesObject

Return all bytes from the file as a byte array.



37
38
39
# File 'lib/talia_core/data_types/file_record.rb', line 37

def all_bytes
  read_all_bytes
end

#get_byte(close_after_single_read = false) ⇒ Object

Returns the next byte from the file (at the position of the read cursor), or EOS if the end of the file has been reached.



43
44
45
# File 'lib/talia_core/data_types/file_record.rb', line 43

def get_byte(close_after_single_read=false)
  next_byte(close_after_single_read)
end

#positionObject

Returns the current position of the read cursor



48
49
50
# File 'lib/talia_core/data_types/file_record.rb', line 48

def position
  return (@position != nil) ? @position : 0
end

#resetObject

Reset the cursor to the beginning of the file



53
54
55
# File 'lib/talia_core/data_types/file_record.rb', line 53

def reset
  set_position(0)
end

#seek(new_position) ⇒ Object

Set a new position for the read cursor



58
59
60
# File 'lib/talia_core/data_types/file_record.rb', line 58

def seek(new_position)
  set_position(new_position)
end

#sizeObject

Returns the file size in bytes



63
64
65
# File 'lib/talia_core/data_types/file_record.rb', line 63

def size
  data_size
end