Skip to content

Commit affbcd7

Browse files
committed
Renamed TnefReader's internal Seek() method to Skip() to more accurately reflect what it does
(it doesn't actually Seek because Seek implies it can go backwards)
1 parent 33cdce6 commit affbcd7

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

MimeKit/Tnef/TnefPropertyReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ byte[] ReadByteArray ()
401401
// remaining bytes are padding
402402
int padding = 4 - (length % 4);
403403

404-
reader.Seek (reader.StreamOffset + padding);
404+
reader.Skip (padding);
405405
}
406406

407407
return bytes;
@@ -610,7 +610,7 @@ public bool ReadNextValue ()
610610

611611
int offset = RawValueStreamOffset + RawValueLength;
612612

613-
if (reader.StreamOffset < offset && !reader.Seek (offset))
613+
if (reader.StreamOffset < offset && !reader.Skip (offset - reader.StreamOffset))
614614
return false;
615615

616616
try {

MimeKit/Tnef/TnefReader.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ internal int ReadInt32 ()
480480

481481
UpdateChecksum (input, inputIndex, 4);
482482

483-
var result = BinaryPrimitives.ReadInt32LittleEndian (input.AsSpan(inputIndex));
483+
var result = BinaryPrimitives.ReadInt32LittleEndian (input.AsSpan (inputIndex));
484484

485485
inputIndex += 4;
486486

@@ -537,15 +537,15 @@ internal double ReadDouble ()
537537
return result;
538538
}
539539

540-
internal bool Seek (int offset)
540+
internal bool Skip (int count)
541541
{
542542
CheckDisposed ();
543543

544-
int left = offset - StreamOffset;
545-
546-
if (left <= 0)
544+
if (count <= 0)
547545
return true;
548546

547+
int left = count;
548+
549549
do {
550550
int n = Math.Min (inputEnd - inputIndex, left);
551551

@@ -570,7 +570,7 @@ bool SkipAttributeRawValue ()
570570
int offset = AttributeRawValueStreamOffset + AttributeRawValueLength;
571571
int expected, actual;
572572

573-
if (!Seek (offset))
573+
if (!Skip (offset - StreamOffset))
574574
return false;
575575

576576
// Note: ReadInt16() will update the checksum, so we need to capture it here

UnitTests/Tnef/TnefReaderTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public void TestReadSingle ()
465465
}
466466

467467
[Test]
468-
public void TestSeekTruncatedLoose ()
468+
public void TestSkipTruncatedLoose ()
469469
{
470470
using (var stream = new MemoryStream ()) {
471471
stream.Write (BitConverter.GetBytes (0x223e9f78), 0, 4);
@@ -482,14 +482,14 @@ public void TestSeekTruncatedLoose ()
482482
stream.Position = 0;
483483

484484
using (var reader = new TnefReader (stream, 0, TnefComplianceMode.Loose)) {
485-
Assert.That (reader.Seek (64), Is.False, "Seek");
485+
Assert.That (reader.Skip (64), Is.False, "Skip");
486486
Assert.That (reader.ComplianceStatus, Is.EqualTo (TnefComplianceStatus.StreamTruncated));
487487
}
488488
}
489489
}
490490

491491
[Test]
492-
public void TestSeekTruncatedStrict ()
492+
public void TestSkipTruncatedStrict ()
493493
{
494494
using (var stream = new MemoryStream ()) {
495495
stream.Write (BitConverter.GetBytes (0x223e9f78), 0, 4);
@@ -507,7 +507,7 @@ public void TestSeekTruncatedStrict ()
507507

508508
using (var reader = new TnefReader (stream, 0, TnefComplianceMode.Strict)) {
509509
try {
510-
reader.Seek (64);
510+
reader.Skip (64);
511511
Assert.Fail ("Seek should have thrown TnefException");
512512
} catch (TnefException ex) {
513513
Assert.That (ex.Error, Is.EqualTo (TnefComplianceStatus.StreamTruncated), "Error");

0 commit comments

Comments
 (0)