package saferio Import Path internal/saferio (on go.dev) Dependency Relation imports 2 packages, and imported by 8 packagesInvolved Source Files Package saferio provides I/O functions that avoid allocating large amounts of memory unnecessarily. This is intended for packages that read data from an [io.Reader] where the size is part of the input data but the input may be corrupt, or may be provided by an untrustworthy attacker.Package-Level Functions (total 3)ReadData reads n bytes from the input stream, but avoids allocating all n bytes if n is large. This avoids crashing the program by allocating all n bytes in cases where n is incorrect. The error is io.EOF only if no bytes were read. If an io.EOF happens after reading some but not all the bytes, ReadData returns io.ErrUnexpectedEOF.ReadDataAt reads n bytes from the input stream at off, but avoids allocating all n bytes if n is large. This avoids crashing the program by allocating all n bytes in cases where n is incorrect.SliceCap returns the capacity to use when allocating a slice. After the slice is allocated with the capacity, it should be built using append. This will avoid allocating too much memory if the capacity is large and incorrect. A negative result means that the value is always too big. The element type is described by passing a pointer to a value of that type. This would ideally use generics, but this code is built with the bootstrap compiler which need not support generics. We use a pointer so that we can handle slices of interface type.
|The pages are generated with Golds v0.6.6. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.|