Comments (5)
@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.
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.
@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
orWriter
from anIO
instance, theIO
is intentionally not closed when theReader
orWriter
is closed. Instead, it needs to be manually closed by the user. Since the user created theIO
externally, theReader
/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 aWriter
with aSocket
(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 theWriter
is closed. So when aWriter
is closed it seeks back to the beginning of the IO to update this info. If a future version supports usingReader
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 aString
or not. This seemed to me a little more direct than checking if the argument responds tosysread
orsyswrite
, which are more specific implementation details of how the gem works internally. I thought about checking if the argument is a descendent ofIO
, but that's not good becauseStringIO
isn't a subclass ofIO
. - I've removed
Reader.file_name
andWriter.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.
@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.
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)
- Possible bug when no block is given to the writer? HOT 2
- No high-level duration info HOT 2
- Example here - https://github.com/jstrait/wavefile/wiki/WaveFile-Tutorial#copying-a-wave-file-to-different-format working correctly? HOT 5
- fyi: ruby-wavefile now packaged for Debian HOT 1
- Duration does not override equality HOT 2
- UnsupportedFormatError HOT 8
- Method to obtain markers/cue points HOT 6
- each_buffer causes ReaderClosedError HOT 3
- Reference for older methods HOT 4
- examples: how create reverse file? HOT 2
- Mix 2 wav files. HOT 2
- Rewind the IO object HOT 4
- Format Chunks With Extra Bytes at the End Sometimes Cause `InvalidFormatError` to be Raised HOT 1
- `Reader` instances can be created for WAVE_FORMAT_EXTENSIBLE files that have an incomplete/missing format chunk extension HOT 1
- Bufer from bytes & mulaw HOT 2
- WaveFile::Reader doesn't work with pipe IO HOT 2
- Sample Data Can't Be Read From a WAVE_FORMAT_EXTENSIBLE File With an Oversized Format Chunk Extension HOT 1
- How i can play file HOT 1
- Misleading error message if "fmt " chunk extension is too large to fit into chunk HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wavefile.