Ruby 的 ZipInputStream 搞砸了我的行结尾是怎么回事?
我很高兴 ZipInputStream 对存储在文件中的行结尾采取不雅的自由,如果它至少能让它们适合我存储文件的平台。 不幸的是,我从 zip 中提取了一个文本文件(.txt、.cpp 等),并且 \n (0x0A) 被替换为 \r\n (0x0d0a),正如您可以想象的那样,这导致给我带来了很大的麻烦。
我可以设置一个标志来告诉它是避免完全更改行结尾还是使用我选择的行结尾之一?
谢谢。
(我已经检查了 zip 文件、我对它的创建等。我已经使用其他 zip 工具提取了它,并验证了它是否已正确存档。我已经使用 rdebug 单步调试了我的项目,发现 ZipInputStream 调用读取() 返回 \r\n 作为行结尾。)
I'd be happy with ZipInputStream taking indecent liberties with the line endings that are stored in a file if it would at least get them right for the platform I'm storing the file on. Unfortunately, I pull a text file (.txt, .cpp. .etc.) out of a zip and the \n (0x0A) gets replaced with a \r\n (0x0d0a) and, as you can imagine, this is causing me a great deal of trouble.
Is there a flag I can set to tell it either to avoid changing the line endings altogether or to use one of my choosing?
Thanks.
(I've checked the zip file, my creation of it, etc. I've extracted it using other zip tools and verified that it is archived properly. I've stepped through my project with rdebug and seen that the ZipInputStream call to read() is returning \r\n for line endings.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的代码中有
open(filename)
或open(filename,"r")
调用,请尝试将其替换为open(filename,"rb ”)
if you have an
open(filename)
oropen(filename,"r")
call in your code, try to replace it withopen(filename,"rb")