Skip to content

Conversation

@BretJohnson
Copy link

Previously, if a zip had deleted entries then enumerating the entries in the zip would throw an exception - the ReadEntry call on a deleted entry would thrown an exception. With this change, deleted entries are instead skipped in the enumeration.

@BretJohnson BretJohnson force-pushed the skip-deleted-items-when-enumerating branch 9 times, most recently from 7f8b3ea to 82617b5 Compare May 15, 2020 00:03
Previously, if a zip had deleted entries then enumerating the entries in the zip would throw an exception - the ReadEntry call on a deleted entry would thrown an exception. With this change, deleted entries are instead skipped in the enumeration.
@BretJohnson BretJohnson force-pushed the skip-deleted-items-when-enumerating branch from 82617b5 to 80b0a8f Compare May 15, 2020 00:05
ZipArchive.cs Outdated
/// <param name="index">index to read</param>
/// <param name="returnNullIfDeleted">whether to return null or throw an exception for deleted entries</param>
/// <returns></returns>
public ZipEntry ReadEntry (ulong index, bool returnNullIfDeleted = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this maybe mirror an example in the BCL? Like Type.GetType:

https://docs.microsoft.com/en-us/dotnet/api/system.type.gettype?view=netcore-3.1#System_Type_GetType_System_String_System_Boolean_

They named this throwOnError, in this case we can default it to true.

This is also an ABI break to use an optional parameter. Can we leave the old method signature in, and just call the other method? (default pass in true)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually had done that at first, and just changed it back, per your suggestion. So now the parameter is throwIfDeleted (since non delete errors always throw) and I updated the API to maintain backward ABI compatibility.

/// <param name="index">index to read</param>
/// <param name="throwIfDeleted">whether to return null or throw an exception for deleted entries</param>
/// <returns></returns>
public ZipEntry ReadEntry (ulong index, bool throwIfDeleted)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably at some point in the future, we'll want to enable C#8 Nullable Reference Types in this repo.

Should we do so, this method would need to return ZipEntry?.

An alternative approach would be to leave this method unchanged as ZipEntry ReadEntry(long index), and add a new method which returns a ZipEntry?.

Thus, a "new' method instead of a ReadEntry() overload.

Question is, what should said new method be named?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We leave it with the same name. Overloads don't need to have identical return types.

@grendello grendello merged commit 2df5b16 into master May 15, 2020
@dellis1972 dellis1972 deleted the skip-deleted-items-when-enumerating branch February 2, 2021 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants