iostreams 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -22
  3. data/Rakefile +45 -0
  4. data/docs/CLAUDE.md +9 -0
  5. data/docs/config.md +161 -0
  6. data/docs/copy_files.md +93 -0
  7. data/docs/extensions.md +125 -0
  8. data/docs/formats.md +816 -0
  9. data/docs/index.md +388 -0
  10. data/docs/path.md +668 -0
  11. data/docs/pgp.md +436 -0
  12. data/docs/streams.md +382 -0
  13. data/docs/tutorial.md +495 -0
  14. data/docs/upgrading.md +664 -0
  15. data/lib/io_streams/builder/deprecations.rb +250 -0
  16. data/lib/io_streams/builder.rb +316 -39
  17. data/lib/io_streams/bzip2/reader.rb +41 -2
  18. data/lib/io_streams/bzip2/writer.rb +35 -2
  19. data/lib/io_streams/deprecation/methods.rb +51 -0
  20. data/lib/io_streams/deprecation/once.rb +27 -0
  21. data/lib/io_streams/deprecation/option_names.rb +26 -0
  22. data/lib/io_streams/deprecation/words.rb +42 -0
  23. data/lib/io_streams/deprecation.rb +259 -0
  24. data/lib/io_streams/encode/reader.rb +58 -3
  25. data/lib/io_streams/encode/writer.rb +23 -2
  26. data/lib/io_streams/encode.rb +99 -0
  27. data/lib/io_streams/errors.rb +55 -0
  28. data/lib/io_streams/gzip/reader.rb +15 -0
  29. data/lib/io_streams/gzip/writer.rb +11 -2
  30. data/lib/io_streams/io_streams.rb +468 -28
  31. data/lib/io_streams/line/reader.rb +9 -3
  32. data/lib/io_streams/line/utf8_reader.rb +23 -0
  33. data/lib/io_streams/path.rb +227 -28
  34. data/lib/io_streams/paths/file.rb +115 -6
  35. data/lib/io_streams/paths/http.rb +92 -5
  36. data/lib/io_streams/paths/matcher.rb +6 -3
  37. data/lib/io_streams/paths/s3.rb +242 -20
  38. data/lib/io_streams/paths/sftp/net_ssh.rb +104 -0
  39. data/lib/io_streams/paths/sftp.rb +141 -57
  40. data/lib/io_streams/paths.rb +23 -0
  41. data/lib/io_streams/pgp/reader.rb +60 -2
  42. data/lib/io_streams/pgp/writer.rb +42 -6
  43. data/lib/io_streams/pgp.rb +92 -21
  44. data/lib/io_streams/reader.rb +54 -1
  45. data/lib/io_streams/record/reader.rb +71 -10
  46. data/lib/io_streams/record/writer.rb +17 -10
  47. data/lib/io_streams/row/header_row.rb +21 -0
  48. data/lib/io_streams/row/reader.rb +52 -15
  49. data/lib/io_streams/row/writer.rb +64 -13
  50. data/lib/io_streams/schema/columns.rb +456 -0
  51. data/lib/io_streams/schema/constraints.rb +99 -0
  52. data/lib/io_streams/schema/field.rb +967 -0
  53. data/lib/io_streams/schema/json_number.rb +56 -0
  54. data/lib/io_streams/schema/keys.rb +78 -0
  55. data/lib/io_streams/schema/pattern.rb +257 -0
  56. data/lib/io_streams/schema/source.rb +31 -0
  57. data/lib/io_streams/schema.rb +616 -0
  58. data/lib/io_streams/stream.rb +843 -69
  59. data/lib/io_streams/symmetric_encryption/reader.rb +12 -0
  60. data/lib/io_streams/symmetric_encryption/writer.rb +4 -0
  61. data/lib/io_streams/tabular/header.rb +60 -4
  62. data/lib/io_streams/tabular/header_mapping.rb +332 -0
  63. data/lib/io_streams/tabular/mapping.rb +165 -0
  64. data/lib/io_streams/tabular/parser/array.rb +5 -0
  65. data/lib/io_streams/tabular/parser/base.rb +34 -0
  66. data/lib/io_streams/tabular/parser/csv.rb +5 -0
  67. data/lib/io_streams/tabular/parser/fixed.rb +200 -1
  68. data/lib/io_streams/tabular/parser/fixed_fields.rb +160 -0
  69. data/lib/io_streams/tabular/parser/hash.rb +10 -0
  70. data/lib/io_streams/tabular/parser/json.rb +17 -0
  71. data/lib/io_streams/tabular/parser/json_fields.rb +132 -0
  72. data/lib/io_streams/tabular/parser/psv.rb +6 -2
  73. data/lib/io_streams/tabular/schema_mapping.rb +361 -0
  74. data/lib/io_streams/tabular.rb +344 -30
  75. data/lib/io_streams/utils.rb +467 -1
  76. data/lib/io_streams/version.rb +1 -1
  77. data/lib/io_streams/writer.rb +37 -1
  78. data/lib/io_streams/xlsx/cells.rb +127 -0
  79. data/lib/io_streams/xlsx/reader.rb +61 -1
  80. data/lib/io_streams/xlsx/schema_reader.rb +90 -0
  81. data/lib/io_streams/xlsx/v3_writer.rb +16 -0
  82. data/lib/io_streams/zip/reader.rb +11 -0
  83. data/lib/io_streams/zip/writer.rb +28 -2
  84. data/lib/iostreams.rb +21 -17
  85. metadata +50 -7
data/docs/tutorial.md ADDED
@@ -0,0 +1,495 @@
1
+ ---
2
+ layout: default
3
+ title: Tutorial
4
+ heading: File / Data Streaming with Ruby
5
+ description: >-
6
+ A step by step introduction to streaming files with IOStreams, from counting
7
+ the lines in a gzip file to reading tabular data out of S3.
8
+ ---
9
+
10
+ If all files were small, they could just be loaded into memory in their entirety.
11
+ However, multi Gigabytes, or even Terabytes in size, loading them into memory is not feasible.
12
+
13
+ In linux it is common to use pipes to stream data between processes.
14
+ For example:
15
+
16
+ ~~~
17
+ # Count the number of lines in a file that has been compressed with gzip
18
+ cat abc.gz | gunzip -c | wc -l
19
+ ~~~
20
+
21
+ For large files it is critical to be able to read and write these files as streams. Ruby has support
22
+ for reading and writing files using streams, but has no built-in way of passing one stream through
23
+ another to support for example compressing the data, encrypting it and then finally writing the result
24
+ to a file. Several streaming implementations exist for languages such as `C++` and `Java` to chain
25
+ together several streams, `IOStreams` offers similar features for Ruby.
26
+
27
+ ~~~ruby
28
+ # Read the first 1024 characters from a compressed file:
29
+ path = IOStreams.path("hello.gz")
30
+ path.reader do |io|
31
+ data = io.read(1024)
32
+ puts "Read: #{data}"
33
+ end
34
+ ~~~
35
+
36
+ The true power of streams is shown when many streams are chained together to achieve the end
37
+ result, without holding the entire file in memory, or ideally without needing to create
38
+ any temporary files to process the stream.
39
+
40
+ ~~~ruby
41
+ # Create a file that is compressed with GZip and then encrypted with Symmetric Encryption:
42
+ path = IOStreams.path("hello.gz.enc")
43
+ path.writer do |io|
44
+ io << "Hello World"
45
+ io << "and some more"
46
+ end
47
+ ~~~
48
+
49
+ The power of the above example applies when the data being written starts to exceed hundreds of megabytes,
50
+ or even gigabytes.
51
+
52
+ By looking at the file name supplied above, IOStreams is able to determine which streams to apply
53
+ to the data being read or written. For example:
54
+ * `hello.zip` => Compressed using Zip
55
+ * `hello.zip.enc` => Compressed using Zip and then encrypted using Symmetric Encryption
56
+ * `hello.gz.enc` => Compressed using GZip and then encrypted using Symmetric Encryption
57
+
58
+ The objective is that all of these streaming processes are performed used streaming
59
+ so that only the current portion of the file is loaded into memory as it moves
60
+ through the entire file.
61
+
62
+ ## Step by Step
63
+
64
+ Install IOStreams gem:
65
+ ~~~
66
+ gem install iostreams --no-doc
67
+ ~~~
68
+
69
+ If you want to follow the AWS S3 examples below install the AWS S3 gem:
70
+ ~~~
71
+ gem install aws-sdk-s3 --no-doc
72
+ ~~~
73
+
74
+ See [Configuring the AWS SDK for Ruby](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html)
75
+ to configure the Ruby AWS library.
76
+
77
+ Open a ruby interactive console:
78
+
79
+ ~~~
80
+ irb
81
+ ~~~
82
+
83
+ Load iostreams:
84
+
85
+ ~~~ruby
86
+ require "iostreams"
87
+ ~~~
88
+
89
+ Reference a file path to hold CSV data and then for fun lets also compress it with GZip:
90
+ ~~~ruby
91
+ path = IOStreams.path("sample/example.csv.gz")
92
+ # => #<IOStreams::Paths::File:sample/example.csv.gz pipeline={:gz=>{}}>
93
+ ~~~
94
+
95
+ The path and file name does not exist yet:
96
+ ~~~ruby
97
+ path.exist?
98
+ # => false
99
+ ~~~
100
+
101
+ If the path `sample` does not exist, it is created automatically during the first write.
102
+ Write CSV data to the file, compressing to GZip as we go.
103
+ ~~~ruby
104
+ path.writer do |io|
105
+ io << "name,login\n"
106
+ io << "Jack Jones,jjones\n"
107
+ io << "Jill Smith,jsmith\n"
108
+ end
109
+ ~~~
110
+
111
+ To verify the data written above, read the entire file:
112
+ ~~~ruby
113
+ path.read
114
+ # => "name,login\nJack Jones,jjones\nJill Smith,jsmith\n"
115
+ ~~~
116
+
117
+ It would be much easier if we could write the CSV data as hashes and let IOStreams deal
118
+ with all the details on how to create properly formatted CSV data:
119
+ ~~~ruby
120
+ path.writer(:hash) do |io|
121
+ io << {name: "Jack Jones", login: "jjones"}
122
+ io << {name: "Jill Smith", login: "jsmith"}
123
+ end
124
+ ~~~
125
+
126
+ Verify the data written by reading the entire file:
127
+ ~~~ruby
128
+ path.read
129
+ # => "name,login\nJack Jones,jjones\nJill Smith,jsmith\n"
130
+ ~~~
131
+
132
+ Now lets read the file one line at a time:
133
+ ~~~ruby
134
+ path.each do |line|
135
+ puts line
136
+ end
137
+ ~~~
138
+ Output:
139
+ ~~~
140
+ name,login
141
+ Jack Jones,jjones
142
+ Jill Smith,jsmith
143
+ ~~~
144
+
145
+ But who wants to do CSV parsing by hand, lets get IOStreams to do that for us by passing `:array` to `each`:
146
+ ~~~ruby
147
+ path.each(:array) do |array|
148
+ p array
149
+ end
150
+ ~~~
151
+ Output:
152
+ ~~~ruby
153
+ ["name", "login"]
154
+ ["Jack Jones", "jjones"]
155
+ ["Jill Smith", "jsmith"]
156
+ ~~~
157
+
158
+ That was better, but we really want a hash back where IOStreams takes care of the CSV header:
159
+ ~~~ruby
160
+ path.each(:hash) do |hash|
161
+ p hash
162
+ end
163
+ ~~~
164
+ Output:
165
+ ~~~ruby
166
+ {"name"=>"Jack Jones", "login"=>"jjones"}
167
+ {"name"=>"Jill Smith", "login"=>"jsmith"}
168
+ ~~~
169
+
170
+ As the file gets larger and we reach millions of rows the above code does not have to change at all.
171
+ And memory utilization stays about the same since each block is read in, decompressed, and parsed
172
+ from CSV one block at a time. The garbage collector can then free the released blocks from memory.
173
+
174
+ Now lets read a zip file hosted on an HTTP Web Server, displaying the first row as a hash:
175
+
176
+ ~~~ruby
177
+ IOStreams.
178
+ path("https://www5.fdic.gov/idasp/Offices2.zip").
179
+ option(:zip, entry_file_name: "OFFICES2_ALL.CSV").
180
+ each(:hash) do |row|
181
+ p row
182
+ # Just show the first line for this tutorial
183
+ break
184
+ end
185
+ ~~~
186
+ Output:
187
+ ~~~ruby
188
+ {"address"=>"1 Lincoln St. Fl 1", "bkclass"=>"SM", "cbsa"=>"Boston-Cambridge-Newton, MA-NH", "cbsa_div"=>"Boston, MA", "cbsa_div_flg"=>"1", "cbsa_div_no"=>"14454", "cbsa_metro"=>"14460", "cbsa_metro_flg"=>"1", "cbsa_metro_name"=>"Boston-Cambridge-Newton, MA-NH", "cbsa_micro_flg"=>"0", "cbsa_no"=>"14460", "cert"=>"14", "city"=>"Boston", "county"=>"Suffolk", "csa"=>"Boston-Worcester-Providence, MA-RI-NH-CT", "csa_flg"=>"1", "csa_no"=>"148", "estymd"=>"1792-01-01", "fi_uninum"=>"6", "mainoff"=>"1", "name"=>"State Street Bank And Trust Company", "offname"=>"State Street Bank And Trust Company", "offnum"=>nil, "rundate"=>"2020-05-14", "servtype"=>"11", "stalp"=>"MA", "stcnty"=>"25025", "stname"=>"Massachusetts", "uninum"=>"6", "zip"=>"2111"}
189
+ ~~~
190
+
191
+ Noticed that it took a while to return the first line?
192
+
193
+ That is because `zip` requires the entire file to be downloaded before it can decompress anything
194
+ in the file. And HTTP uses a push protocol when reading files, so it is downloaded automatically
195
+ into a temp file behind the scenes so that we can read it as if it was a local file.
196
+
197
+ ## Same Code - Varying File Types
198
+
199
+ Lets define a method to write data to a file.
200
+ ~~~ruby
201
+ def write_lines(file_name)
202
+ path = IOStreams.path(file_name)
203
+ path.writer do |io|
204
+ io << "name,login\n"
205
+ io << "Jack Jones,jjones\n"
206
+ io << "Jill Smith,jsmith\n"
207
+ end
208
+ end
209
+ ~~~
210
+
211
+ Create some sample files to work with
212
+ ~~~ruby
213
+ write_lines("sample/example.csv")
214
+ write_lines("sample/example.csv.gz")
215
+ ~~~
216
+
217
+ For PGP files we also need to specify the recipient that can decrypt the file.
218
+ ~~~ruby
219
+ path = IOStreams.path("sample/example.csv.pgp")
220
+ path.option(:pgp, recipient: "receiver@example.org")
221
+ write_lines(path)
222
+ ~~~
223
+
224
+ `IOStreams.path` takes a string as its argument, it can also accept an existing instance of `IOStreams`.
225
+ That allows the same method to accept the pgp recipient without having to pass the pgp specific recipient information
226
+ as an argument to the method.
227
+
228
+ Consider a simple method to display the contents of a file a line at a time
229
+ prefixed with the line number within the file:
230
+ ~~~ruby
231
+ def show_lines(file_name)
232
+ line_number = 1
233
+ path = IOStreams.path(file_name)
234
+ path.each(:line) do |line|
235
+ puts "[#{line_number}] #{line}"
236
+ line_number += 1
237
+ end
238
+ end
239
+ ~~~
240
+
241
+ Lets read all of the files created above with the new `show_lines` method:
242
+
243
+ ~~~ruby
244
+ show_lines("sample/example.csv")
245
+ show_lines("sample/example.csv.gz")
246
+ show_lines("sample/example.csv.pgp")
247
+ ~~~
248
+
249
+ Noticed how they all returned the exact same output, even though the first file was plain text, the second was
250
+ compressed with Gzip and the third was encrypted with PGP. They all returned:
251
+ ~~~
252
+ [1] name,login
253
+ [2] Jack Jones,jjones
254
+ [3] Jill Smith,jsmith
255
+ ~~~
256
+
257
+ Now a program can be developed using IOStreams and then without any code changes is able read plain text, compressed,
258
+ or encrypted files.
259
+
260
+ ## Same Code - Any File Storage
261
+
262
+ Using the unchanged `write_lines` and `show_lines` methods above, lets use them to read and write from S3.
263
+
264
+ But how is that possible since our program / methods above were only tested against local files?
265
+
266
+ Create the same sample files to work with, but this time on AWS S3 in a bucket name `my-iostreams-bucket`
267
+ ~~~ruby
268
+ write_lines("s3://my-iostreams-bucket/sample/example.csv")
269
+ write_lines("s3://my-iostreams-bucket/sample/example.csv.gz")
270
+ ~~~
271
+
272
+ For PGP files we also need to specify the recipient that can decrypt the file.
273
+ ~~~ruby
274
+ path = IOStreams.path("s3://my-iostreams-bucket/sample/example.csv.pgp")
275
+ path.option(:pgp, recipient: "receiver@example.org")
276
+ write_lines(path)
277
+ ~~~
278
+
279
+ The only change to switch to S3 storage was to prefix the file name passed in with `s3://my-iostreams-bucket/`.
280
+
281
+ Lets read all of the files created above with the new `show_lines` method:
282
+
283
+ ~~~ruby
284
+ show_lines("s3://my-iostreams-bucket/sample/example.csv")
285
+ show_lines("s3://my-iostreams-bucket/sample/example.csv.gz")
286
+ show_lines("s3://my-iostreams-bucket/sample/example.csv.pgp")
287
+ ~~~
288
+
289
+ Noticed how they all returned the exact same output, even though the first file was plain text, the second was
290
+ compressed with Gzip and the third was encrypted with PGP. They all returned:
291
+ ~~~
292
+ [1] name,login
293
+ [2] Jack Jones,jjones
294
+ [3] Jill Smith,jsmith
295
+ ~~~
296
+
297
+ Now a program can be developed using IOStreams and then without any code changes is able to read and write across
298
+ multiple storage locations.
299
+
300
+ ### Configure storage once, not in every call
301
+
302
+ In the examples above we still wrote the `s3://my-iostreams-bucket/` prefix into every call, which
303
+ means the code itself decides where files are stored. The real goal is for the application code to
304
+ say nothing at all about storage, so the same code can run unchanged against local files in
305
+ development and S3 in production.
306
+
307
+ Roots make that possible. Configure the storage location once in a startup initializer:
308
+ ~~~ruby
309
+ # config/initializers/iostreams.rb (development)
310
+ IOStreams.add_root(:default, "tmp/files")
311
+ ~~~
312
+
313
+ Then use `IOStreams.join` instead of `IOStreams.path`, and never mention the storage location again:
314
+ ~~~ruby
315
+ def write_lines(file_name)
316
+ path = IOStreams.join(file_name)
317
+ path.writer do |io|
318
+ io << "name,login\n"
319
+ io << "Jack Jones,jjones\n"
320
+ io << "Jill Smith,jsmith\n"
321
+ end
322
+ end
323
+
324
+ write_lines("sample/example.csv")
325
+ write_lines("sample/example.csv.gz")
326
+ ~~~
327
+
328
+ To run the exact same code against S3 in production, change only the initializer:
329
+ ~~~ruby
330
+ # config/initializers/iostreams.rb (production)
331
+ IOStreams.add_root(:default, "s3://my-iostreams-bucket/files")
332
+ ~~~
333
+
334
+ The application code does not change at all. See [Configuring IOStreams](config) for multiple roots,
335
+ for example separate locations for downloads, uploads, and reports.
336
+
337
+ ## Tabular Files
338
+
339
+ Tabular files are any files that start with a header row and then follows with rows of data with each row
340
+ on a separate line.
341
+
342
+ For example "example.csv"
343
+ ~~~
344
+ name,login
345
+ Jack Jones,jjones
346
+ Jill Smith,jsmith
347
+ ~~~
348
+
349
+ The first line contains the header: `name,login`
350
+ Each subsequent line contains the data delimited by a special character such as `,` in the same order as the header.
351
+
352
+ Another example is PSV (Pipe Separated Files)
353
+ ~~~
354
+ name|login
355
+ Jack Jones|jjones
356
+ Jill Smith|jsmith
357
+ ~~~
358
+
359
+ Of course these are simple examples and there are lots of rules on how to embed or escape the row or column delimiters.
360
+
361
+ ### Reading Tabular Files
362
+
363
+ When reading these files, IOStreams can handle the complexity of the files format and always return the data as a
364
+ `hash`, or `array`.
365
+
366
+ Lets create another method along the lines of `show_lines` above:
367
+ ~~~ruby
368
+ def show_rows(file_name)
369
+ line_number = 1
370
+ path = IOStreams.path(file_name)
371
+ path.each(:hash) do |row|
372
+ puts "[#{line_number}] #{row.inspect}"
373
+ line_number += 1
374
+ end
375
+ end
376
+ ~~~
377
+
378
+ The key difference is that `:hash` is being passed into `each` instead of `:line`.
379
+
380
+ Using the sample files created above:
381
+ ~~~ruby
382
+ show_rows("sample/example.csv")
383
+ ~~~
384
+
385
+ Outputs:
386
+ ~~~
387
+ [1] {"name"=>"Jack Jones", "login"=>"jjones"}
388
+ [2] {"name"=>"Jill Smith", "login"=>"jsmith"}
389
+ ~~~
390
+
391
+ Notice how only 2 rows are returned, since the header row is not actual data, it is just the definition of the
392
+ rows that follow.
393
+
394
+ The same method works without changes regardless of where the file was stored, or whether it was encrypted or
395
+ compressed.
396
+ ~~~ruby
397
+ show_rows("s3://my-iostreams-bucket/sample/example.csv")
398
+ show_rows("s3://my-iostreams-bucket/sample/example.csv.gz")
399
+ show_rows("s3://my-iostreams-bucket/sample/example.csv.pgp")
400
+ ~~~
401
+
402
+ ### Writing Tabular Files
403
+
404
+ Lets define a new method that uses a tabular api to write the data.
405
+ ~~~ruby
406
+ def write_tabular(file_name)
407
+ path = IOStreams.path(file_name)
408
+ path.writer(:hash) do |io|
409
+ io << {"name"=>"Jack Jones", "login"=>"jjones"}
410
+ io << {"name"=>"Jill Smith", "login"=>"jsmith"}
411
+ end
412
+ end
413
+ ~~~
414
+
415
+ The key difference is that `:hash` is being passed into `writer` to indicate that it will receive hashes instead of
416
+ raw data.
417
+
418
+ Lets create a sample file, and then read it to compare its contents to the raw writer above.
419
+ ~~~ruby
420
+ write_tabular("sample/example.csv")
421
+ IOStreams.path("sample/example.csv").read
422
+ # => "name,login\nJack Jones,jjones\nJill Smith,jsmith\n"
423
+ ~~~
424
+
425
+ Note how the output file is identical to the one created above.
426
+ Using `writer(:hash)` makes it easier to develop the application without regard for:
427
+ - The order of columns
428
+ - Missing columns
429
+ - Specialized escaping of values to handle row or column delimiters
430
+
431
+ Note: The first row written determines the column names as well as the order of the elements to be written.
432
+ To set the columns up front, in your own order, describe them with a [schema](formats#schema) on the path: its
433
+ fields are the columns, in order, and `fieldsMatch: "subset"` skips the other keys of each record:
434
+ ~~~ruby
435
+ path = IOStreams.path("sample/logins.csv").schema(
436
+ fieldsMatch: "subset",
437
+ fields: [{name: "login"}, {name: "name"}]
438
+ )
439
+ path.writer(:hash) do |io|
440
+ io << {"name" => "Jack Jones", "login" => "jjones", "notes" => "Not written"}
441
+ io << {"login" => "jsmith", "name" => "Jill Smith"}
442
+ end
443
+ path.read
444
+ # => "login,name\njjones,Jack Jones\njsmith,Jill Smith\n"
445
+ ~~~
446
+
447
+ Now lets write the same data into a JSON file, then read it to see what it looks like:
448
+ ~~~ruby
449
+ write_tabular("sample/example.json")
450
+ puts IOStreams.path("sample/example.json").read
451
+ # => "{\"name\":\"Jack Jones\",\"login\":\"jjones\"}\n{\"name\":\"Jill Smith\",\"login\":\"jsmith\"}\n"
452
+ ~~~
453
+
454
+ Using the same `show_rows` method above to display the file line by line
455
+ ~~~ruby
456
+ show_rows("sample/example.json")
457
+ ~~~
458
+
459
+ Outputs the same data even though the file is now json instead of the previous file that was csv:
460
+ ~~~
461
+ [1] {"name"=>"Jack Jones", "login"=>"jjones"}
462
+ [2] {"name"=>"Jill Smith", "login"=>"jsmith"}
463
+ ~~~
464
+
465
+ The same method works without changes regardless of where the file was stored, or whether it was encrypted or
466
+ compressed, or whether the format was csv or json.
467
+ ~~~ruby
468
+ show_rows("sample/example.csv")
469
+ show_rows("sample/example.json")
470
+ show_rows("s3://my-iostreams-bucket/sample/example.csv")
471
+ show_rows("s3://my-iostreams-bucket/sample/example.json.gz")
472
+ show_rows("s3://my-iostreams-bucket/sample/example.json.pgp")
473
+ ~~~
474
+
475
+ ## Conclusion
476
+
477
+ IOStreams makes it possible to write an application to a common api so that
478
+ * the file can be accessed anywhere ( at least a local file, AWS S3, HTTP(S) and SFTP for now).
479
+ * the application does not care if or how the file was compressed.
480
+ * the application does not care if or how the file was encrypted.
481
+ * the actual file storage mechanism can be determined at runtime, or per environment.
482
+ * it is transparent whether the application receives an Excel Spreadsheet, CSV, or PSV formatted file.
483
+ It just works with hashes when desired.
484
+
485
+ IOStreams is an incredibly powerful streaming library that makes changes to file formats, compression, encryption,
486
+ or storage mechanism transparent to the application.
487
+
488
+ ## Next Steps
489
+
490
+ Move onto the [IOStreams Path Documentation](path) to see how to create paths that support AWS S3, HTTP(S), or SFTP.
491
+
492
+ Or jump straight into the [IOStreams Streams Documentation](streams) for detailed information on working with streams.
493
+
494
+ Read the [IOStreams PGP Documentation](pgp) for a tutorial on how to work with PGP Encrypted files.
495
+