简体   繁体   English

通过mingw在Windows上的gzstream:注入CR + LF

[英]gzstream on windows via mingw: injects CR + LF

I downloaded the source from the site and built it but when I run the test, all of the zipped files have CR+LF line endings rather than just LF which makes the unzipped files different from the originals. 我从网站上下载了源代码并进行了构建,但是当我运行测试时,所有压缩文件都具有CR + LF行尾,而不仅仅是LF,这使得解压缩后的文件与原始文件不同。

I'm looking at the source but it seems like they are already opening the file in binary mode: 我正在查看源代码,但似乎他们已经在以二进制模式打开文件了:

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 = '\0';
    file = gzopen( name, fmode);
    if (file == 0)
        return (gzstreambuf*)0;
    opened = 1;
    return this;
}

I'd really like to use this bit of code because it looks very clean and it compiled effortlessly on mingw gcc. 我真的很想使用这段代码,因为它看起来很干净并且可以在mingw gcc上轻松编译。 The only problem is this tricky business which I could let slide if I can figure out a solution for it. 唯一的问题是这个棘手的业务,如果我能找到解决方案的话,我可以放手。

I've successfully implemented my workaround. 我已经成功实施了解决方法。 Though gzstream looks nice I bit the bullet and just wrote some code that directly uses zlib. 尽管gzstream看起来不错,但我还是硬着头皮写了一些直接使用zlib的代码。 Turns out it wasn't bad at all because zlib has helpers hidden away in there, and also plenty of helpful comments in zlib.h itself. 事实证明,这一点都还不错因为zlib中隐藏了帮助程序,并且zlib.h本身也包含了许多有用的注释。

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

And of course, no more problems with spurious 0x0D carriage-return chars! 当然,伪造的0x0D回车字符也不再有问题!

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

On UNIX platforms it is often unnecessary so some people omit it when they should not. 在UNIX平台上,这通常是不必要的,因此某些人在不需要的时候会忽略它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM