node-warc icon indicating copy to clipboard operation
node-warc copied to clipboard

WARC Parsing sometimes results in truncated records.

Open ikreymer opened this issue 6 years ago • 7 comments

The WARC parsing sometimes results in records being truncated.

This might be due to the parser continuing to look for newlines/read one line at a time, even when parsing the content body, and might be happening if there is a \r\n\r\n encountered in the body of the record.

The issue can be seen by running:

const { AutoWARCParser } = require('node-warc');
  
(async () => {
  for await (const record of new AutoWARCParser('test1.warc.gz')) {
    console.log(record.content.toString('utf-8'));
  }
})();

With these example files: test1.warc.gz (last couple of bytes are cut-off)

test2.warc.gz (most of the file is cut-off after initial comment)

For comparison, the warcio version prints the full record:

from warcio import ArchiveIterator
  
for record in ArchiveIterator(open('./test1.warc.gz', 'rb')):
    print(record.content_stream().read().decode('utf-8'))

ikreymer avatar Jul 22 '19 15:07 ikreymer

I'm trying to parse the contents as well (especially HTML) and most of the sites return the HTML truncated.

comatory avatar Sep 01 '19 13:09 comatory

I'm experiencing this also. Seems like the issue is warcRecord/builder.js .. the function consumeLine() ... basically you're using a solo CRLF as the boundary between WARC Records... seems to me that you should be ignoring this until you reach the WARC Record's Content-Length

chichicuervo avatar Apr 01 '20 05:04 chichicuervo

seems that commenting out the line this._parsingState = parsingStates.consumeCRLFContent2

inside the switch statement resolves this specific problem. Is there a specific protocol reason it's there, like trailers or something, or were you just trying to avoid trailing CRLFs?

chichicuervo avatar Apr 01 '20 05:04 chichicuervo

The aim of crlf content two was to skip the trailing CRLFs between records. For more details see the spec.

If that fixes the issue for all cases feel free to open a PR. I am working on this albeit slowly on the updates branch. Also feel free to add to the effort via a PR.

N0taN3rd avatar Apr 05 '20 04:04 N0taN3rd

Also @ikreymer still waiting on that PR fixing this you said you had

N0taN3rd avatar Apr 05 '20 04:04 N0taN3rd

Hey, here is the fix that I have in builder.js: https://github.com/ikreymer/node-warc/commit/e5bfd2fd3e14a8debba11d85b732252a1cb343f0

I could isolate that and make it into a PR, not 100% sure it fixes it, but think so.. I had a bunch of other changes on that branch though.

ikreymer avatar Apr 05 '20 04:04 ikreymer

@chichicuervo in case this helps you, I wanted to mention I've been working on a new WARC reader library focusing on streaming WARCs in the browser: https://github.com/ikreymer/warcio.js It works comparable to the python warcio library and should not have the truncation issue.

It's not as far along as this library and doesn't yet have support for writing WARCs, though.

ikreymer avatar Apr 14 '20 23:04 ikreymer