@@ -21,6 +21,7 @@ import (
2121 "io"
2222 "strconv"
2323 "strings"
24+ "time"
2425)
2526
2627const (
@@ -38,6 +39,9 @@ type WarcRecord interface {
3839 Type () RecordType
3940 WarcHeader () * WarcFields
4041 Block () Block
42+ RecordId () string
43+ ContentLength () (int64 , error )
44+ Date () (time.Time , error )
4145 String () string
4246 io.Closer
4347 // ToRevisitRecord takes RevisitRef referencing the record we want to make a revisit of and returns a revisit record.
@@ -192,8 +196,20 @@ func (wr *warcRecord) Block() Block {
192196 return wr .block
193197}
194198
199+ func (wr * warcRecord ) RecordId () string {
200+ return wr .headers .GetId (WarcRecordID )
201+ }
202+
203+ func (wr * warcRecord ) ContentLength () (int64 , error ) {
204+ return wr .headers .GetInt64 (ContentLength )
205+ }
206+
207+ func (wr * warcRecord ) Date () (time.Time , error ) {
208+ return wr .headers .GetTime (WarcDate )
209+ }
210+
195211func (wr * warcRecord ) String () string {
196- return fmt .Sprintf ("WARC record: version: %s, type: %s, id: %s" , wr .version , wr .Type (), wr .WarcHeader ().Get (WarcRecordID ))
212+ return fmt .Sprintf ("WARC record: version: %s, type: %s, id: %s" , wr .version , wr .Type (), wr .WarcHeader ().GetId (WarcRecordID ))
197213}
198214
199215func (wr * warcRecord ) Close () error {
@@ -227,7 +243,7 @@ func (wr *warcRecord) ToRevisitRecord(ref *RevisitRef) (WarcRecord, error) {
227243 h .Set (WarcType , Revisit .String ())
228244 h .Set (WarcProfile , ref .Profile )
229245 if ref .TargetRecordId != "" {
230- h .Set (WarcRefersTo , ref .TargetRecordId )
246+ h .SetId (WarcRefersTo , ref .TargetRecordId )
231247 }
232248 if ref .TargetUri != "" {
233249 h .Set (WarcRefersToTargetURI , ref .TargetUri )
@@ -242,7 +258,7 @@ func (wr *warcRecord) ToRevisitRecord(ref *RevisitRef) (WarcRecord, error) {
242258 return nil , err
243259 }
244260 h .Set (WarcBlockDigest , block .BlockDigest ())
245- h .Set (ContentLength , strconv . Itoa ( len (block .headerBytes ) ))
261+ h .SetInt (ContentLength , len (block .headerBytes ))
246262
247263 revisit := & warcRecord {
248264 opts : wr .opts ,
@@ -261,7 +277,7 @@ func (wr *warcRecord) RevisitRef() (*RevisitRef, error) {
261277
262278 return & RevisitRef {
263279 Profile : wr .headers .Get (WarcProfile ),
264- TargetRecordId : wr .headers .Get (WarcRefersTo ),
280+ TargetRecordId : wr .headers .GetId (WarcRefersTo ),
265281 TargetUri : wr .headers .Get (WarcRefersToTargetURI ),
266282 TargetDate : wr .headers .Get (WarcRefersToDate ),
267283 }, nil
@@ -274,7 +290,7 @@ func (wr *warcRecord) CreateRevisitRef(profile string) (*RevisitRef, error) {
274290
275291 return & RevisitRef {
276292 Profile : profile ,
277- TargetRecordId : wr .headers .Get (WarcRecordID ),
293+ TargetRecordId : wr .headers .GetId (WarcRecordID ),
278294 TargetUri : wr .headers .Get (WarcTargetURI ),
279295 TargetDate : wr .headers .Get (WarcDate ),
280296 }, nil
@@ -309,21 +325,21 @@ func (wr *warcRecord) Merge(record ...WarcRecord) (WarcRecord, error) {
309325 }
310326 switch v := record [0 ].Block ().(type ) {
311327 case * httpRequestBlock :
312- refLen , err := strconv . ParseInt ( record [0 ].WarcHeader ().Get (ContentLength ), 10 , 64 )
328+ refLen , err := record [0 ].WarcHeader ().GetInt64 (ContentLength )
313329 if err != nil {
314330 return nil , fmt .Errorf ("could not parse %s" , ContentLength )
315331 }
316332 size := int64 (len (b .headerBytes )) + refLen - int64 (len (v .httpHeaderBytes ))
317- wr .headers .Set (ContentLength , strconv . FormatInt ( size , 10 ) )
333+ wr .headers .SetInt64 (ContentLength , size )
318334 v .httpHeaderBytes = b .headerBytes
319335 wr .block = v
320336 case * httpResponseBlock :
321- refLen , err := strconv . ParseInt ( record [0 ].WarcHeader ().Get (ContentLength ), 10 , 64 )
337+ refLen , err := record [0 ].WarcHeader ().GetInt64 (ContentLength )
322338 if err != nil {
323339 return nil , fmt .Errorf ("could not parse %s" , ContentLength )
324340 }
325341 size := int64 (len (b .headerBytes )) + refLen - int64 (len (v .httpHeaderBytes ))
326- wr .headers .Set (ContentLength , strconv . FormatInt ( size , 10 ) )
342+ wr .headers .SetInt64 (ContentLength , size )
327343 v .httpHeaderBytes = b .headerBytes
328344 wr .block = v
329345 default :
0 commit comments