Source file src/internal/exportdata/support.go

     1  // Copyright 2024 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This file contains support functions for exportdata.
     6  
     7  package exportdata
     8  
     9  import (
    10  	"bufio"
    11  	"io"
    12  	"strconv"
    13  	"strings"
    14  )
    15  
    16  // Copy of cmd/internal/archive.ReadHeader.
    17  func readArchiveHeader(b *bufio.Reader, name string) int {
    18  	// architecture-independent object file output
    19  	const HeaderSize = 60
    20  
    21  	var buf [HeaderSize]byte
    22  	if _, err := io.ReadFull(b, buf[:]); err != nil {
    23  		return -1
    24  	}
    25  	aname := strings.Trim(string(buf[0:16]), " ")
    26  	if !strings.HasPrefix(aname, name) {
    27  		return -1
    28  	}
    29  	asize := strings.Trim(string(buf[48:58]), " ")
    30  	i, _ := strconv.Atoi(asize)
    31  	return i
    32  }
    33  

View as plain text