Giter VIP home page Giter VIP logo

Comments (8)

jetersen avatar jetersen commented on June 11, 2024 1

Most stream API have an option for leave open, which would be a good approach imho.

from easycompressor.

mjebrahimi avatar mjebrahimi commented on June 11, 2024

Interesting point.ย 
Let me examine the problem.

from easycompressor.

mjebrahimi avatar mjebrahimi commented on June 11, 2024

We have 4 approaches to solve this problem.

1- Adding leaveOutputStreamOpen parameter to Compress methods since Compress methods currentlty dispose only the output stream. (which passed to Encoder/Compressor stream like LZ4Stream.Encode(outputStream) )
And adding leaveInputStreamOpen parameters to Decompress methods since Decompress methods currently dispose only the input stream. (which passed to Decoder/Decompressor stream like LZ4Stream.Decode(inputStream) )

2- Adding an option (like LeaveOpenSettings) that has two property (leaveOutputStreamOpen and leaveInputStreamOpen) to Compress and Decompress methods to determine which input/output streams must be disposed after operation completes.

3- And Adding just one leaveOpen parameter to both Compress and Decompress methods to leave open both input and output streams if it is true and dispose them manually if it is false.
Note: In this way, we have breaking changes because these methods dispose both streams (something that has not been done before) if it is false (By default, the leaveOpen parameter will be false)

Note: All three approaches above will require method signature changes and for CompressAsync and DecompressAsync that has CancellationToken as the third parameter currently (instead of leaveOpen) cause breaking changes but we can fix this problem by adding two extension methods to ICompressor that gives CancellationToken as the third parameter and pass the default value (false) to leaveOpen at the method call to main Compress/Decompress methods.

4- No adding any parameter to Compress and Decompress methods. Just pass leaveOpen: true to underlying Encoder/Decoder streams to prevent from disposing input and output streams. (like LZ4Stream.Encode(outputStream, leaveOpen: true))
Note: In with way, unlike previous approaches we have not any method signature changes.
But we have a minimum breaking changes because Compress/Decompress methods no longer dispose any streams (something that has not been done before).

IMO, approach 4 is better choice because require no method signature changes and also disposing the streams is not related to Compress/Decompress methods and it is not their jobs.

Now, what do you think? I would like to know your opinion.

from easycompressor.

mjebrahimi avatar mjebrahimi commented on June 11, 2024

Currently, this test (that checks streams are not closed after Compress/Decompress completes)ย is passed regard to approach 4 (passing leaveOpen: true to underlying Encoder/Decoder streams without adding any parameters to Compress/Decompress methods)

from easycompressor.

jetersen avatar jetersen commented on June 11, 2024

I think approach four is suitable as it would usually be surrounded by a stream with an using statement.

from easycompressor.

mjebrahimi avatar mjebrahimi commented on June 11, 2024

I also agree.
Version 1.4.0 was released in order to fix this issue.

from easycompressor.

jetersen avatar jetersen commented on June 11, 2024

@mjebrahimi thanks for fixing the issue :)

from easycompressor.

mjebrahimi avatar mjebrahimi commented on June 11, 2024

@jetersen thank you for the report and contribution.

from easycompressor.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.