Method: FileUploadObject.split_to_small_files

Defined in:
lib/notion_ruby_mapping/objects/file_upload_object.rb

.split_to_small_files(org_file, max_size = MAX_SIZE) ⇒ Object

Raises:

  • (StandardError)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/notion_ruby_mapping/objects/file_upload_object.rb', line 70

def self.split_to_small_files(org_file, max_size = MAX_SIZE)
  raise StandardError, "File does not exist: #{org_file}" unless File.exist?(org_file)

  temp_files = []
  File.open(org_file, "rb") do |file|
    until file.eof?
      chunk = file.read(max_size)
      temp_file = Tempfile.new("part_")
      temp_file.binmode
      temp_file.write(chunk)
      temp_file.rewind
      temp_files << temp_file
    end
  end
  temp_files
end