Skip to content

Raise if tried to stream #211

@doits

Description

@doits

When streaming (= a block is passed to download) it only downloads a chunk for the file here and returns nil to the caller:

def download
result = super

This leads to the following error when doing something like ActiveStorage::Attachment.last.download { |chunk| }

TypeError (can't convert NilClass to String):

/gems/lockbox-2.0.1/lib/lockbox/encryptor.rb:72:in 'Lockbox::Encryptor#check_string'
/gems/lockbox-2.0.1/lib/lockbox/encryptor.rb:24:in 'Lockbox::Encryptor#decrypt'
/gems/lockbox-2.0.1/lib/lockbox/utils.rb:113:in 'block in Lockbox::Utils.decrypt_result'
/gems/lockbox-2.0.1/lib/lockbox/utils.rb:112:in 'Lockbox::Utils.decrypt_result'
/gems/lockbox-2.0.1/lib/lockbox/active_storage_extensions.rb:91:in 'Lockbox::ActiveStorageExtensions::Attachment#download'

In addition the block receives the first chunk of encrypted data first (before the exception is raised) which I think is not expected, too.

I think it should raise like it does below, for example do this:

      def download
        raise Lockbox::Error, "Streaming not supported for encrypted files" if block_given?

        result = super

Edit: I guess it should raise for download_chunk, too?

Wdyt?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions