While taking either a stream or a string filename gives maximal compatibility it's entirely possible to hand pyembroidery an invalid stream. Such as one opened in textmode to write a format that requires binary. This should be detected an an error should be raised rejecting unacceptable stream modes. It also might be possible to reopen a stream in the correct mode, in some cases though .name could be a file descriptor instead so better to just raise an error.
While taking either a stream or a string filename gives maximal compatibility it's entirely possible to hand pyembroidery an invalid stream. Such as one opened in textmode to write a format that requires binary. This should be detected an an error should be raised rejecting unacceptable stream modes. It also might be possible to reopen a stream in the correct mode, in some cases though .name could be a file descriptor instead so better to just raise an error.