Reads VPK file header from the file
557629
def read_header(self):
        
        with fopen(self.vpk_path, 'rb') as f:
            (self.signature,
             self.version,
             self.tree_length
             ) = struct.unpack("3I", f.read(3*4))

            # original format - headerless
            if self.signature != 0x55aa1234:
                raise ValueError("File is not VPK (invalid magic)")
            # v1
            elif self.version == 1:
                self.header_length += 4*3
            # v2 with extended header
            #
            # according to http://forum.xentax.com/viewtopic.php?f=10&t=11208
            # struct VPKDirHeader_t
            # {
            #    int32 m_nHeaderMarker;
            #    int32 m_nVersion;
            #    int32 m_nDirectorySize;
            #    int32 m_nEmbeddedChunkSize;
            #    int32 m_nChunkHashesSize;
            #    int32 m_nSelfHashesSize;
            #    int32 m_nSignatureSize;
            # }
            elif self.version == 2:
                (self.embed_chunk_length,
                 self.chunk_hashes_length,
                 self.self_hashes_length,
                 self.signature_length
                 ) = struct.unpack("4I", f.read(4*4))
                self.header_length += 4*7

                f.seek(self.tree_length + self.embed_chunk_length + self.chunk_hashes_length, 1)

                assert self.self_hashes_length == 48, "Self hashes section size mismatch"

                (self.tree_checksum,
                 self.chunk_hashes_checksum,
                 self.file_checksum,
                 ) = struct.unpack("16s16s16s", f.read(16*3))
            else:
                raise ValueError("Invalid header, or unsupported version")
877138
def _read_top_header(self):
    """"""
    magic = self._fh.read(4)
    l_text = struct.unpack('<i',self._fh.read(4))[0]
    header_text = self._fh.read(l_text).rstrip('\0')
    n_ref = struct.unpack('<i',self._fh.read(4))[0]
    return header_text, n_ref
802801
public static VcfHeader header(final File file) throws IOException {
        checkNotNull(file);
        // could also use Files.asCharSource(file, Charsets.UTF_8).openBufferedStream()
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            return header(reader);
        }
    }
913114
def read_vpcs_stdout(self):
        

        output = ""
        if self._vpcs_stdout_file:
            try:
                with open(self._vpcs_stdout_file, "rb") as file:
                    output = file.read().decode("utf-8", errors="replace")
            except OSError as e:
                log.warn("Could not read {}: {}".format(self._vpcs_stdout_file, e))
        return output
691869
public void readHeader(InputStream in) throws IOException {
        CRC32 crc = new CRC32();
        crc.reset();
        if (!testGzipMagic(in, crc)) {
            throw new NoGzipMagicException();
        }
        this.length += 2;
        if (readByte(in, crc) != Deflater.DEFLATED) {
            throw new IOException("Unknown compression");
        }
        this.length++;
       
        // Get gzip header flag.
        this.flg = readByte(in, crc);
        this.length++;
        
        // Get MTIME.
        this.mtime = readInt(in, crc);
        this.length += 4;
        
        // Read XFL and OS.
        this.xfl = readByte(in, crc);
        this.length++;
        this.os = readByte(in, crc);
        this.length++;
        
        // Skip optional extra field -- stuff w/ alexa stuff in it.
        final int FLG_FEXTRA = 4;
        if ((this.flg & FLG_FEXTRA) == FLG_FEXTRA) {
            int count = readShort(in, crc);
            this.length +=2;
            this.fextra = new byte[count];
            readByte(in, crc, this.fextra, 0, count);
            this.length += count;
        }   
        
        // Skip file name.  It ends in null.
        final int FLG_FNAME  = 8;
        if ((this.flg & FLG_FNAME) == FLG_FNAME) {
            while (readByte(in, crc) != 0) {
                this.length++;
            }
        }   
        
        // Skip file comment.  It ends in null.
        final int FLG_FCOMMENT = 16;   // File comment
        if ((this.flg & FLG_FCOMMENT) == FLG_FCOMMENT) {
            while (readByte(in, crc) != 0) {
                this.length++;
            }
        }
        
        // Check optional CRC.
        final int FLG_FHCRC  = 2;
        if ((this.flg & FLG_FHCRC) == FLG_FHCRC) {
            int calcCrc = (int)(crc.getValue() & 0xffff);
            if (readShort(in, crc) != calcCrc) {
                throw new IOException("Bad header CRC");
            }
            this.length += 2;
        }
    }
340541
@Override
  public void readHeader(RandomAccessFile file) throws IOException {
    file.seek(0);
    if(file.readInt() != FILE_VERSION) {
      throw new RuntimeException("File " + file + " is not a PersistentPageFile or wrong version!");
    }

    this.pageSize = file.readInt();
  }
207616
function parseHeader(headers) {
  // Returns a header object with keys header line types (.e.g format, info,
  // sample) and values arrays of objects containing the key-value information
  // stored therein.
  if (headers.length === 0) {
    throw new Error('Invalid VCF File: missing header.');
  }

  var header = {};
  header.__RAW__ = headers;
  // VCF header lines always start with either one or two # signs.
  headers = U.map(headers, function(h) { return h.replace(/^##?/, ""); });

  header.columns = headers[headers.length-1].split('\t');
  header.sampleNames = header.columns.slice(NUM_STANDARD_HEADER_COLUMNS);

  // TODO(ihodes): parse other, less frequently used, header lines like
  //               'assembly'
  header.VERSION = parseVCFVersion(headers);
  header.ALT = parseHeadersOf('ALT', headers);
  header.INFO = parseHeadersOf('INFO', headers);
  header.FORMAT = parseHeadersOf('FORMAT', headers);
  header.SAMPL = parseHeadersOf('SAMPLE', headers);
  header.PEDIGREE = parseHeadersOf('PEDIGREE', headers);
  header.contig = parseHeadersOf('contig', headers);

  return header;
}
993883
def read_machine_header(data):
    
    if isinstance(data, (bytes, bytearray)):
        stream = io.BytesIO(data)
    elif isinstance(data, io.BufferedReader):
        stream = data
    else:
        raise ValueError("data should be either bytearray or file 'rb' mode.")

    header = dict()
    header_type = stream.read(6)
    if header_type == b"#!\x00\x01@\x00":
        header['type'] = header_type[2:6]
        header['time'] = struct.unpack('>I', stream.read(4))[0]
        header['meta_type'] = struct.unpack('>I', stream.read(4))[0]
        header['meta_len'] = struct.unpack('>I', stream.read(4))[0]
        header['data_type'] = struct.unpack('>I', stream.read(4))[0]
        header['data_len'] = struct.unpack('>I', stream.read(4))[0]
        stream.read(4)
    elif header_type == b"#~DF02":
        header['type'] = header_type[2:6]
        header['meta_type'] = stream.read(2)
        header['meta_len'] = struct.unpack('>I', stream.read(4))[0]
        header['data_len'] = struct.unpack('>I', stream.read(4))[0]
        stream.read(4)
    else:
        raise NotImplementedError(
            "Parser for machine header %s not implemented" %
            (header_type.decode()))

    return header
1043358
def _read(self):
        
        if self._dask:
            d = da.from_delayed(
                delayed(read_from_bpch, )(
                    self.filename, self.file_position, self.shape,
                    self.dtype, self.endian, use_mmap=self._mmap
                ),
                self.shape, self.dtype
            )
        else:
            d = read_from_bpch(
                    self.filename, self.file_position, self.shape,
                    self.dtype, self.endian, use_mmap=self._mmap
            )

        return d
896447
def read_chd_header(chd_file):
    

    with open(chd_file, "rb") as f:
        header = {
            "cinefileheader": cine.CINEFILEHEADER(),
            "bitmapinfoheader": cine.BITMAPINFOHEADER(),
            "setup": cine.SETUP(),
        }
        f.readinto(header["cinefileheader"])
        f.readinto(header["bitmapinfoheader"])
        f.readinto(header["setup"])

    return header
499247
private function read_header()
    {
        $this->seek(0, IO::SEEK_SET);

        $magic = $this->read(DataIO::magic_size());

        if (strlen($magic) < DataIO::magic_size())
            throw new DataIoException(
                'Not an Avro data file: shorter than the Avro magic block');

        if (DataIO::magic() != $magic) {

            throw new DataIoException(
                sprintf('Not an Avro data file: %s does not match %s',
                    $magic, DataIO::magic()));
        }

        $this->metadata = $this->datum_reader->read_data(DataIO::metadata_schema(),
            DataIO::metadata_schema(),
            $this->decoder);
        $this->sync_marker = $this->read(DataIO::SYNC_SIZE);
    }
996744
protected function readCentralFileHeader()
    {
        $binary_data = fread($this->fh, 46);
        $header      = unpack(
            'vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset',
            $binary_data
        );

        if ($header['filename_len'] != 0) {
            $header['filename'] = fread($this->fh, $header['filename_len']);
        } else {
            $header['filename'] = '';
        }

        if ($header['extra_len'] != 0) {
            $header['extra'] = fread($this->fh, $header['extra_len']);
            $header['extradata'] = $this->parseExtra($header['extra']);
        } else {
            $header['extra'] = '';
            $header['extradata'] = array();
        }

        if ($header['comment_len'] != 0) {
            $header['comment'] = fread($this->fh, $header['comment_len']);
        } else {
            $header['comment'] = '';
        }

        $header['mtime']           = $this->makeUnixTime($header['mdate'], $header['mtime']);
        $header['stored_filename'] = $header['filename'];
        $header['status']          = 'ok';
        if (substr($header['filename'], -1) == '/') {
            $header['external'] = 0x41FF0010;
        }
        $header['folder'] = ($header['external'] == 0x41FF0010 || $header['external'] == 16) ? 1 : 0;

        return $header;
    }
594123
def _read_mesafile(filename,data_rows=0,only='all'):
    
    f=open(filename,'r')
    vv=[]
    v=[]
    lines = []
    line  = ''
    for i in range(0,6):
        line = f.readline()
        lines.extend([line])

    hval  = lines[2].split()
    hlist = lines[1].split()
    header_attr = {}
    for a,b in zip(hlist,hval):
        header_attr[a] = float(b)
    if only is 'header_attr':
        return header_attr

    cols    = {}
    colnum  = lines[4].split()
    colname = lines[5].split()
    for a,b in zip(colname,colnum):
        cols[a] = int(b)

    data = []

    old_percent = 0
    for i in range(data_rows):
        # writing reading status
        percent = int(i*100/np.max([1, data_rows-1]))
        if percent >= old_percent + 5:
            sys.stdout.flush()
            sys.stdout.write("\r reading " + "...%d%%" % percent)
            old_percent = percent
        line = f.readline()
        v=line.split()
        try:
            vv=np.array(v,dtype='float64')
        except ValueError:
            for item in v:
                if item.__contains__('.') and not item.__contains__('E'):
                    v[v.index(item)]='0'
        data.append(vv)

    print(' \n')
    f.close()
    a=np.array(data)
    data = []
    return header_attr, cols, a
545742
def read_header(filename):
    '''  '''
    header = {}
    in_header = False
    data = nl.universal_read(filename)
    lines = [x.strip() for x in data.split('\n')]
    for line in lines:
        if line=="*** Header Start ***":
            in_header=True
            continue
        if line=="*** Header End ***":
            return header
        fields = line.split(": ")
        if len(fields)==2:
            header[fields[0]] = fields[1]
426203
def read_tvips_header(fh, byteorder, dtype, count, offsetsize):
    """"""
    result = {}
    header = fh.read_record(TIFF.TVIPS_HEADER_V1, byteorder=byteorder)
    for name, typestr in TIFF.TVIPS_HEADER_V1:
        result[name] = header[name].tolist()
    if header['Version'] == 2:
        header = fh.read_record(TIFF.TVIPS_HEADER_V2, byteorder=byteorder)
        if header['Magic'] != int(0xaaaaaaaa):
            log.warning('read_tvips_header: invalid TVIPS v2 magic number')
            return {}
        # decode utf16 strings
        for name, typestr in TIFF.TVIPS_HEADER_V2:
            if typestr.startswith('V'):
                s = header[name].tostring().decode('utf16', errors='ignore')
                result[name] = stripnull(s, null='\0')
            else:
                result[name] = header[name].tolist()
        # convert nm to m
        for axis in 'XY':
            header['PhysicalPixelSize' + axis] /= 1e9
            header['PixelSize' + axis] /= 1e9
    elif header.version != 1:
        log.warning('read_tvips_header: unknown TVIPS header version')
        return {}
    return result
493230
def read_file(pth, use_str=False):
    
    cont = None
    try:
        with open(u'' + pth, 'rb') as fp:
            cont = fp.read()

        if use_str:
            cont = to_str(cont)
    except Exception as err:
        print(err)
    return cont
271416
private void readHeader(RandomAccessInputStream raf) throws IOException
	{
		raf.seek(HEAD_LOCATION);

		byte[] head = new byte[HEAD_SIZE];
		if (raf.read(head) != HEAD_SIZE)
		{
			throw new IOException("Error encountered reading id3v2 header");
		}

		majorVersion = (int) head[3];

		if (majorVersion <= NEW_MAJOR_VERSION)
		{
			minorVersion = (int) head[4];
			unsynchronisation = (head[5]&0x80)!=0;
			extended = (head[5]&0x40)!=0;
			experimental = (head[5]&0x20)!=0;
			footer = (head[5]&0x10)!=0;
			tagSize = Helpers.convertDWordToInt(head, 6);
		}
	}