Movatterモバイル変換


[0]ホーム

URL:


saferio

packagestandard library
go1.25.5Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License:BSD-3-ClauseImports:2Imported by:0

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

Package saferio provides I/O functions that avoid allocating largeamounts of memory unnecessarily. This is intended for packages thatread data from anio.Reader where the size is part of the inputdata but the input may be corrupt, or may be provided by anuntrustworthy attacker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcReadData

func ReadData(rio.Reader, nuint64) ([]byte,error)

ReadData reads n bytes from the input stream, but avoids allocatingall n bytes if n is large. This avoids crashing the program byallocating 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.

funcReadDataAt

func ReadDataAt(rio.ReaderAt, nuint64, offint64) ([]byte,error)

ReadDataAt reads n bytes from the input stream at off, but avoidsallocating all n bytes if n is large. This avoids crashing the programby allocating all n bytes in cases where n is incorrect.

funcSliceCap

func SliceCap[Eany](cuint64)int

SliceCap is like SliceCapWithSize but using generics.

funcSliceCapWithSizeadded ingo1.22.0

func SliceCapWithSize(size, cuint64)int

SliceCapWithSize returns the capacity to use when allocating a slice.After the slice is allocated with the capacity, it should bebuilt using append. This will avoid allocating too much memoryif the capacity is large and incorrect.

A negative result means that the value is always too big.

Types

This section is empty.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp