-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: archive/zip: *File should implement fmt.Stringer #23260
Comments
/cc @dsnet |
Not that I'm opposed to a
|
The problem with "friendly String methods" for complex types, especially in core packages, is that different people have different definitions of what that might mean. In this case I think it's better to leave it as and have you print the things you're interested in. |
@robpike - I think it'd be useful as it is, minus the every byte being printed, i.e. name and compression level. |
@judepereira that might be something to open a Go2 issue about: a flag that truncates long slices/arrays e.g.: https://play.golang.org/p/zWL3C7jRlIR |
@ericlagergren A flag wouldn't do justice to it, unless by default, the String method would return a shorthand representation of the array. Instead of a flag, maybe we could have String always return a shorthand description of the array, and then a new method, say, Contents which would return the current implementation (i.e. the actual array contents)? |
something along the line of jar -tvf ? |
@MironAtHome That could be part of a new API in zip (although I think one exists already - haven't looked). I was thinking of something on the lines of the file name, and file size. After all, it is the String impl for File, and not zip. |
Sorry, but you can easily forget and print just about every struct that exists. That doesn't mean every struct should have a String method. It's also unclear whether String should return the name, the content, or (as you suggested) some "ls -l"-like summary. Better not to pick one and let people ask for what they want. |
I recently made the mistake of printing a *zip.File while debugging some zip reader code, expecting it to show me the name and perhaps the mode of the zip entry in some helpful form. It did show me these things, because fmt printed the raw struct, they were followed by masses of decimal numbers---the value of every byte in the file.
Here's one of the smaller lines of output:
Ideally *File would have a friendly String method.
The text was updated successfully, but these errors were encountered: