Determine file type (binary or text)
David C. Fox
davidcfox at post.harvard.edu
Thu Aug 14 16:04:36 CEST 2003
Sami Viitanen wrote:
> Thanks for the answers.
> To be more specific I'm making a script that should
> identify binary files as binary and text files as text.
> The script is for automating CVS commands and
> with CVS you have to add the -kb flag to
> add (or import) binary files. (because it can't itself
> determine what type the file is). If binary file is not
> added with -kb the results are awful.
You should note that the question of when to use -kb is not simply based
on the contents of the file, but on whether you want CVS/RCS to try to
merge conflicting versions.
For example, I recently added some files containing pickled objects
(used as test data sets for a regression test) to the CVS repository for
my project. Although the pickle files are in fact all printable text, a
CVS/RCS merge of two valid pickle files won't yield a valid pickle file.
Therefore, I used -kb to ensure that the developer would always be
forced to choose a version in the event of a version conflict.
More information about the Python-list