Skip to content

Commit

Permalink
Rework the IO wrapper stack (#59)
Browse files Browse the repository at this point in the history
* Remove rubyzip adapter and test
* Remove IO wrappers
* Rework the IO wrapper stack

The IO wrappers were not really needed except in tests. Also, some work needed to be done to allow the gem to use the ZipKit streaming helper, as there were questions about how to stream from Rails.
  • Loading branch information
julik authored Dec 28, 2024
1 parent fbb5c33 commit c054056
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 432 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 2.5.0 (2020-06-27)
## 3.0.0 (unreleased)

- Change dependency from zip_tricks to zip_kit
- Allow ZipKit streamer to be passed in as output destination. In that case the Streamer can be closed externally
- Remove IO wrappers and leave just the ZIP output wrapper, as it is the only one which would produce useable output
- Ensure the gem can use the ZipKit Rails streaming helper for output
- Switch from Travis-CI to Github Actions

## 2.4.0 (2020-06-27)

Expand Down
41 changes: 22 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Xlsxtream

[![Gem Version](https://badge.fury.io/rb/xlsxtream.svg)](https://rubygems.org/gems/xlsxtream)
[![Build Status](https://travis-ci.org/felixbuenemann/xlsxtream.svg)](https://travis-ci.org/felixbuenemann/xlsxtream)

Xlsxtream is a streaming writer for XLSX spreadsheets. It supports multiple worksheets and optional string
deduplication via a shared string table (SST). Its purpose is to replace CSV for large exports, because using
Expand Down Expand Up @@ -33,7 +32,7 @@ Or install it yourself as:
## Usage

```ruby
# Creates a new workbook and closes it at the end of the block
# Creates a new workbook file, write and close it at the end of the block
Xlsxtream::Workbook.open('my_data.xlsx') do |xlsx|
xlsx.write_worksheet 'Sheet1' do |sheet|
# Boolean, Date, Time, DateTime and Numeric are properly mapped
Expand Down Expand Up @@ -108,35 +107,39 @@ Xlsxtream::Workbook.new(io, columns: [
])
# The :columns option can also be given to write_worksheet, so it's
# possible to have multiple worksheets with different column widths.
```


# Output from Rails (will stream without buffering)
class ReportsController < ApplicationController
include ZipKit::RailsStreaming
EXCEL_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

def download
zip_kit_stream(filename: "report.xlsx", type: EXCEL_CONTENT_TYPE) do |zip_kit_streamer|
Xlsxtream::Workbook.open(zip_kit_streamer) do |xlsx|
xlsx.write_worksheet 'Sheet1' do |sheet|
# Boolean, Date, Time, DateTime and Numeric are properly mapped
sheet << [true, Date.today, 'hello', 'world', 42, 3.14159265359, 42**13]
end
end
end
end
end
```

## Compatibility

The current version of Xlsxtream requires at least Ruby 2.1.0.
The current version of Xlsxtream requires at least Ruby 2.6

If you are using an older Ruby version you can use the following in your Gemfile:

```ruby
gem 'xlsxtream', '< 2'
gem 'xlsxtream', '< 3'
```

* The last version with support for Ruby 1.9.1 is 1.2.0.
* The last version with support for Ruby 1.9.2 is 1.3.2.

## Upgrading

If you are upgrading from a version earlier than 2.x and are using the undocumented `:io_wrapper` option you need to update your code:

```ruby
# Pre 2.x code with :io_wrapper option
Xlsxtream::Workbook.new(io, io_wrapper: MyCustomIOWrapper)
# New code with IO wrapper instance
io_wrapper = MyCustomIOWrapper.new(io)
Xlsxtream::Workbook.new(io_wrapper)
```

Every IO-like object that responds to `:add_file` is treated as an IO wrapper.
* The last version with support for Ruby 2.1.x is 2.4.x

## Development

Expand Down
28 changes: 0 additions & 28 deletions lib/xlsxtream/io/directory.rb

This file was deleted.

47 changes: 0 additions & 47 deletions lib/xlsxtream/io/hash.rb

This file was deleted.

31 changes: 0 additions & 31 deletions lib/xlsxtream/io/rubyzip.rb

This file was deleted.

26 changes: 0 additions & 26 deletions lib/xlsxtream/io/stream.rb

This file was deleted.

45 changes: 0 additions & 45 deletions lib/xlsxtream/io/zip_kit.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/xlsxtream/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module Xlsxtream
VERSION = '2.4.0'.freeze
VERSION = '3.0.0'
end
Loading

0 comments on commit c054056

Please sign in to comment.