gzstream在windows上通过mingw注入CR + LF

gzstream on windows via mingw: injects CR + LF

本文关键字:注入 CR LF mingw windows gzstream      更新时间:2023-10-16

我从站点下载了源代码并构建了它,但是当我运行测试时,所有压缩的文件都有CR+LF行结尾,而不仅仅是LF,这使得解压缩的文件与原始文件不同。

我正在查看源代码,但似乎他们已经以二进制模式打开了文件:

gzstreambuf* gzstreambuf::open( const char* name, int open_mode) {
    if ( is_open())
        return (gzstreambuf*)0;
    mode = open_mode;
    // no append nor read/write mode
    if ((mode & std::ios::ate) || (mode & std::ios::app)
        || ((mode & std::ios::in) && (mode & std::ios::out)))
        return (gzstreambuf*)0;
    char  fmode[10];
    char* fmodeptr = fmode;
    if ( mode & std::ios::in)
        *fmodeptr++ = 'r';
    else if ( mode & std::ios::out)
        *fmodeptr++ = 'w';
    *fmodeptr++ = 'b';
    *fmodeptr = '';
    file = gzopen( name, fmode);
    if (file == 0)
        return (gzstreambuf*)0;
    opened = 1;
    return this;
}

我真的很喜欢使用这段代码,因为它看起来非常干净,而且在mingw gcc上编译起来毫不费力。唯一的问题是这件棘手的事情,如果我能想出一个解决方案,我可以让它顺其自然。

我已经成功地实现了我的解决方案。虽然gzstream看起来不错,但我还是硬着头写了一些直接使用zlib的代码。事实证明,一点也不坏,因为zlib在那里隐藏了帮助器,而且zlib.h本身也有很多有用的评论。

ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen));很简单。

当然,没有更多的问题与伪0x0D回车字符!

std::ios::binary在哪里??

在UNIX平台上,它通常是不必要的,所以有些人在不应该省略它的时候忽略了它。