Skip to content

Handle 'rw' files correctly in __init__() #59

@mgeier

Description

@mgeier

The problem is that 'rw' files can be two quite different things: either existing files or new files.
If it's a new file, some arguments are required (like channels, subtype etc.), if it's an already existing file, those arguments are forbidden (except for 'RAW' files).

As far as I know, there is no function in libsndfile that allows to check before opening which of the two cases we're dealing with.

I see three options which could theoretically work:

  1. Use a function from the Python standard library to check if the file already exists
  2. Try to open the file with libsndfile. If there is an error, check if the reason are the required arguments. If there is no error, check if any of the forbidden arguments were given and raise an error.
  3. Split 'rw' mode into two distinct modes, one that only works for existing files and another one that only works for new files (or alternatively, it can also delete the existing file content first, like 'w+' mode does in Python's open() function)

Are there more options?

I'm currently leaning towards option 3, see also #60.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions