stack.go
func (s *Stack) Push(header, data []byte) (depth int, err error) {
	s.guard.Lock()
	defer s.guard.Unlock()
	s.lastAccess = time.Now()
	file, err := s.getFile()
	if err != nil {
		return -1, err
	}
	// Seek to place for next block
	currentOffset, err := file.Seek(s.currentBlock.NextBlockPoint(), os.SEEK_SET)
	if err != nil {
		return -1, err
	}
	// Get place for payload
	bodyOffset := currentOffset + fileBlockDefineSize
	block := fileBlock{
		PrevBlock:   uint64(s.currentBlockPos),
		HeaderPoint: uint64(bodyOffset),
		HeaderSize:  uint64(len(header)),
		DataPoint:   uint64(bodyOffset) + uint64(len(header)),
		DataSize:    uint64(len(data)),
	}
	// Write block meta-info
	err = binary.Write(file, binary.LittleEndian, block)
	if err != nil {
		file.Seek(currentOffset, os.SEEK_SET)
		return -1, err
	}
	// Write header
	_, err = file.Write(header)
	if err != nil {
		file.Seek(currentOffset, os.SEEK_SET)
		return -1, err
	}
	// Write data
	_, err = file.Write(data)
	if err != nil {
		file.Seek(currentOffset, os.SEEK_SET)
		return -1, err
	}
	s.depth++
	s.currentBlockPos = currentOffset
	s.currentBlock = block
	return s.depth, nil
}
func (s *Stack) Push(header, data []byte) (depth int, err error) {
	s.guard.Lock()
	defer s.guard.Unlock()
	s.lastAccess = time.Now()
	file, err := s.getFile()
	if err != nil {
		return -1, err
	}
	// Seek to place for next block
	currentOffset, err := file.Seek(s.currentBlock.NextBlockPoint(), os.SEEK_SET)
	if err != nil {
		return -1, err
	}
	// Get place for payload
	bodyOffset := currentOffset + fileBlockDefineSize
	block := fileBlock{
		PrevBlock:   uint64(s.currentBlockPos),
		HeaderPoint: uint64(bodyOffset),
		HeaderSize:  uint64(len(header)),
		DataPoint:   uint64(bodyOffset) + uint64(len(header)),
		DataSize:    uint64(len(data)),
	}
	// Write block meta-info
	err = binary.Write(file, binary.LittleEndian, block)
	if err != nil {
		file.Seek(currentOffset, os.SEEK_SET)
		return -1, err
	}
	// Write header
	_, err = file.Write(header)
	if err != nil {
		file.Seek(currentOffset, os.SEEK_SET)
		return -1, err
	}
	// Write data
	_, err = file.Write(data)
	if err != nil {
		file.Seek(currentOffset, os.SEEK_SET)
		return -1, err
	}
	s.depth++
	s.currentBlockPos = currentOffset
	s.currentBlock = block
	return s.depth, nil
}
// Push header and body to stack. Returns new value of stack depth