Code Monkey home page Code Monkey logo

Comments (5)

taf2 avatar taf2 commented on May 30, 2024 1

@jstrait - I have a need to avoid writing to disk where were are dealing with a large number wave files and converting them to different formats, downloading the wave file and upload the resulting mp3 for example. With the IO object we can achieve this and avoid touching the disk in the process which improves our throughput.

from wavefile.

jstrait avatar jstrait commented on May 30, 2024

Sorry for taking awhile to respond. I can see the benefit of this in theory - is there a specific use case where this would be helpful for you?

Passing in an IO object to the new constructors instead of a pathname (as in your examples above) is nice in that it makes the gem agnostic to where it is reading/writing. However, what I don't like as much is that it puts more work on the caller to manually open the file. For my own use, I've only ever wanted to read/write to a file, so this seems like adding extra work without clear gain. Maybe there's a use case I'm not thinking of.

Another option could be to add a different method that allows constructing an instance from an IO object.

from wavefile.

jstrait avatar jstrait commented on May 30, 2024

@taf2 thanks for the additional context, that makes sense.

I've added support for this on the v0.8.0 branch, and it will be included as a feature in that release. I expect it to be released soon.

Out of curiosity, is this still a feature that would be helpful for you for the reasons you mentioned above? It won't change whether this feature gets added either way, I'm just curious how people are using this gem.

Thanks for opening #22 - I appreciate it! I decided to go with that API, where the argument to Reader/Writer constructor can either be a String for the file name, or an IO object. I like that because it's backwards compatible with the existing interface.

I ended up building a different implementation though, and added some additional changes:

  • When constructing a Reader or Writer from an IO instance, the IO is intentionally not closed when the Reader or Writer is closed. Instead, it needs to be manually closed by the user. Since the user created the IO externally, the Reader/Writer shouldn't make assumptions about what the user wants to do with it.
  • One drawback of supporting generic IO is that there are issues with IO instances that don't support seeking. For example, I don't think you can use a Writer with a Socket (although I haven't actually tried it out). The reason is that Wave files include data in the file header about the size of the file, and this can't be known until all data has been written and the Writer is closed. So when a Writer is closed it seeks back to the beginning of the IO to update this info. If a future version supports using Reader to seek to an arbitrary sample frame, this would also be an issue. But at the end of the day, it feels to me like the benefit of supporting other types of IO outweighs this drawback.
  • I changed the logic that determines if the constructor argument is a file name or an IO instance. It now checks if the argument is a String or not. This seemed to me a little more direct than checking if the argument responds to sysread or syswrite, which are more specific implementation details of how the gem works internally. I thought about checking if the argument is a descendent of IO, but that's not good because StringIO isn't a subclass of IO.
  • I've removed Reader.file_name and Writer.file_name from the v0.8.0 branch, because it doesn't necessarily have a sensible value when reading/writing from an IO, and I don't know of an obvious use case for these fields.

Check out the v0.8.0 branch if you're interested to see the current implementation or try it out. Please let me know if you have any feedback.

Because of the alternate implementation, I'll also close #22.

from wavefile.

taf2 avatar taf2 commented on May 30, 2024

@jstrait - excellent, yeah your implementation is better to leave control of the IO object to the client since they created it. Backwards compatibility is always the way to go thanks!

from wavefile.

jstrait avatar jstrait commented on May 30, 2024

v0.8.0 has been released, so this feature should now be available. Let me know if you run into any issues!

from wavefile.

Related Issues (20)

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.