Module: IOStreams::Deprecated::ClassMethods
- Defined in:
- lib/io_streams/deprecated.rb
Instance Method Summary collapse
-
#compressed?(file_name) ⇒ Boolean
DEPRECATED.
-
#copy(source_file_name_or_io, target_file_name_or_io, buffer_size: nil, source_options: {}, target_options: {}) ⇒ Object
Copies the source file/stream to the target file/stream.
-
#each_line(file_name_or_io, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED.
-
#each_record(file_name_or_io, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED.
-
#each_row(file_name_or_io, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED.
-
#encrypted?(file_name) ⇒ Boolean
DEPRECATED.
-
#line_reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED.
-
#line_writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED.
-
#reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, &block) ⇒ Object
DEPRECATED.
-
#reader_stream?(file_name_or_io) ⇒ Boolean
DEPRECATED.
-
#record_reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED.
-
#record_writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED.
-
#row_reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED.
-
#row_writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED.
-
#writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, &block) ⇒ Object
DEPRECATED.
-
#writer_stream?(file_name_or_io) ⇒ Boolean
DEPRECATED.
Instance Method Details
#compressed?(file_name) ⇒ Boolean
DEPRECATED. Use Path#compressed?
160 161 162 |
# File 'lib/io_streams/deprecated.rb', line 160 def compressed?(file_name) Path.new(file_name).compressed? end |
#copy(source_file_name_or_io, target_file_name_or_io, buffer_size: nil, source_options: {}, target_options: {}) ⇒ Object
Copies the source file/stream to the target file/stream. Returns [Integer] the number of bytes copied
Example: Copy between 2 files
IOStreams.copy('a.csv', 'b.csv')
Example: Read content from a Xlsx file and write it out in CSV form.
IOStreams.copy('a.xlsx', 'b.csv')
Example:
# Read content from a JSON file and write it out in CSV form.
#
# The output header for the CSV file is extracted from the first row in the JSON file.
# If the first JSON row does not contain all the column names then they will be ignored
# for the rest of the file.
IOStreams.copy('a.json', 'b.csv')
Example:
# Read a PSV file and write out a CSV file from it.
IOStreams.copy('a.psv', 'b.csv')
Example:
# Copy between 2 files, encrypting the target file with Symmetric Encryption
# Since the target file_name already includes `.enc` in the filename, it is automatically
# encrypted.
IOStreams.copy('a.csv', 'b.csv.enc')
Example:
# Copy between 2 files, encrypting the target file with Symmetric Encryption
# Since the target file_name does not include `.enc` in the filename, to encrypt it
# the encryption stream is added.
IOStreams.copy('a.csv', 'b', target_options: [:enc])
Example:
# Copy between 2 files, encrypting the target file with Symmetric Encryption
# Since the target file_name does not include `.enc` in the filename, to encrypt it
# the encryption stream is added, along with the optional compression option.
IOStreams.copy('a.csv', 'b', target_options: [enc: { compress: true }])
Example:
# Create a pgp encrypted file.
# For PGP Encryption the recipients email address is required.
IOStreams.copy('a.xlsx', 'b.csv.pgp', target_options: [:csv, pgp: { recipient_email: '[email protected]' }])
Example: Copy between 2 existing streams
IOStreams.reader('a.csv') do |source_stream|
IOStreams.writer('b.csv.enc') do |target_stream|
IOStreams.copy(source_stream, target_stream)
end
end
Example:
# Copy between 2 csv files, reducing the number of columns present and encrypting the
# target file with Symmetric Encryption
output_headers = %w[name address]
IOStreams.copy(
'a.csv',
'b.csv.enc',
target_options: [csv:{headers: output_headers}, enc: {compress: true}]
)
Example:
# Copy a locally encrypted file to AWS S3.
# Decrypts the file, then compresses it with gzip as it is being streamed into S3.
# Useful for when the entire bucket is encrypted on S3.
IOStreams.copy('a.csv.enc', 's3://my_bucket/b.csv.gz')
140 141 142 143 144 145 146 147 |
# File 'lib/io_streams/deprecated.rb', line 140 def copy(source_file_name_or_io, target_file_name_or_io, buffer_size: nil, source_options: {}, target_options: {}) # TODO: prevent stream conversions when reader and writer streams are the same! reader(source_file_name_or_io, **) do |source_stream| writer(target_file_name_or_io, **) do |target_stream| IO.copy_stream(source_stream, target_stream) end end end |
#each_line(file_name_or_io, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED
26 27 28 29 |
# File 'lib/io_streams/deprecated.rb', line 26 def each_line(file_name_or_io, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) path = build_path(file_name_or_io, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.each(:line, **args, &block) end |
#each_record(file_name_or_io, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED
38 39 40 41 |
# File 'lib/io_streams/deprecated.rb', line 38 def each_record(file_name_or_io, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) path = build_path(file_name_or_io, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.each(:hash, **args, &block) end |
#each_row(file_name_or_io, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED
32 33 34 35 |
# File 'lib/io_streams/deprecated.rb', line 32 def each_row(file_name_or_io, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) path = build_path(file_name_or_io, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.each(:array, **args, &block) end |
#encrypted?(file_name) ⇒ Boolean
DEPRECATED. Use Path#encrypted?
165 166 167 |
# File 'lib/io_streams/deprecated.rb', line 165 def encrypted?(file_name) Path.new(file_name).encrypted? end |
#line_reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED
170 171 172 173 |
# File 'lib/io_streams/deprecated.rb', line 170 def line_reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) path = build_path(file_name_or_io, streams: streams, file_name: file_name, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.reader(:line, **args, &block) end |
#line_writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED
57 58 59 60 |
# File 'lib/io_streams/deprecated.rb', line 57 def line_writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) path = build_path(file_name_or_io, streams: streams, file_name: file_name, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.writer(:line, **args, &block) end |
#reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, &block) ⇒ Object
20 21 22 23 |
# File 'lib/io_streams/deprecated.rb', line 20 def reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, &block) path = build_path(file_name_or_io, streams: streams, file_name: file_name, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.reader(&block) end |
#reader_stream?(file_name_or_io) ⇒ Boolean
DEPRECATED
150 151 152 |
# File 'lib/io_streams/deprecated.rb', line 150 def reader_stream?(file_name_or_io) file_name_or_io.respond_to?(:read) end |
#record_reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED
182 183 184 185 |
# File 'lib/io_streams/deprecated.rb', line 182 def record_reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) path = build_path(file_name_or_io, streams: streams, file_name: file_name, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.reader(:hash, **args, &block) end |
#record_writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED
69 70 71 72 |
# File 'lib/io_streams/deprecated.rb', line 69 def record_writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) path = build_path(file_name_or_io, streams: streams, file_name: file_name, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.writer(:hash, **args, &block) end |
#row_reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED
176 177 178 179 |
# File 'lib/io_streams/deprecated.rb', line 176 def row_reader(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) path = build_path(file_name_or_io, streams: streams, file_name: file_name, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.reader(:line, **args, &block) end |
#row_writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) ⇒ Object
DEPRECATED
63 64 65 66 |
# File 'lib/io_streams/deprecated.rb', line 63 def row_writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args, &block) path = build_path(file_name_or_io, streams: streams, file_name: file_name, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.writer(:array, **args, &block) end |
#writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, &block) ⇒ Object
DEPRECATED. Use ‘#path` or `#io` Examples:
IOStreams.path("data.zip").writer { |f| f.write("Hello World") }
IOStreams.path(file_name).option(:encode, encoding: "BINARY").writer { |f| f.write("Hello World") }
io_stream = StringIO.new("Hello World")
IOStreams.stream(io_stream).writer { |f| f.write("Hello World") }
51 52 53 54 |
# File 'lib/io_streams/deprecated.rb', line 51 def writer(file_name_or_io, streams: nil, file_name: nil, encoding: nil, encode_cleaner: nil, encode_replace: nil, &block) path = build_path(file_name_or_io, streams: streams, file_name: file_name, encoding: encoding, encode_cleaner: encode_cleaner, encode_replace: encode_replace) path.writer(&block) end |
#writer_stream?(file_name_or_io) ⇒ Boolean
DEPRECATED
155 156 157 |
# File 'lib/io_streams/deprecated.rb', line 155 def writer_stream?(file_name_or_io) file_name_or_io.respond_to?(:write) end |