當前位置: 首頁>>代碼示例>>Golang>>正文


Golang File.Open方法代碼示例

本文整理匯總了Golang中github.com/indyjo/cafs.File.Open方法的典型用法代碼示例。如果您正苦於以下問題:Golang File.Open方法的具體用法?Golang File.Open怎麽用?Golang File.Open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/indyjo/cafs.File的用法示例。


在下文中一共展示了File.Open方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: dispatchWorkAndSaveEncryptedResult

func (a *SellActivity) dispatchWorkAndSaveEncryptedResult(log bitwrk.Logger, workFile cafs.File) error {
	// Watch transaction state and close connection to worker when transaction expires
	connChan := make(chan io.Closer)
	exitChan := make(chan bool)
	go a.watchdog(log, exitChan, connChan, func() bool { return a.tx.State == bitwrk.StateActive })
	defer func() {
		exitChan <- true
	}()

	st := NewScopedTransport()
	connChan <- st
	defer st.Close()

	reader := workFile.Open()
	defer reader.Close()
	result, err := a.worker.DoWork(reader, NewClient(&st.Transport))
	if err != nil {
		return err
	}
	defer result.Close()

	temp := a.manager.storage.Create(fmt.Sprintf("Sell #%v: encrypted result", a.GetKey()))
	defer temp.Dispose()

	// Use AES-256 to encrypt the result
	block, err := aes.NewCipher(a.encResultKey[:])
	if err != nil {
		return err
	}

	// Create OFB stream with null initialization vector (ok for one-time key)
	var iv [aes.BlockSize]byte
	stream := cipher.NewOFB(block, iv[:])

	writer := &cipher.StreamWriter{S: stream, W: temp}
	_, err = io.Copy(writer, result)
	if err != nil {
		return err
	}

	if err := temp.Close(); err != nil {
		return err
	}

	if err := result.Close(); err != nil {
		return err
	}

	a.execSync(func() { a.encResultFile = temp.File() })

	return nil
}
開發者ID:TimSylvester,項目名稱:bitwrk,代碼行數:52,代碼來源:client2client.go

示例2: dispatchWork

func (a *SellActivity) dispatchWork(log bitwrk.Logger, workFile cafs.File) (io.ReadCloser, error) {
	// Watch transaction state and close connection to worker when transaction expires
	connChan := make(chan io.Closer)
	exitChan := make(chan bool)
	go a.watchdog(log, exitChan, connChan, func() bool { return a.tx.State == bitwrk.StateActive })
	defer func() {
		exitChan <- true
	}()

	reader := workFile.Open()
	defer reader.Close()

	st := NewScopedTransport()
	connChan <- st
	defer st.Close()
	r, err := a.worker.DoWork(reader, NewClient(&st.Transport))
	if err == nil {
		// Defuse connection closing mechanism
		st.DisownConnections()
	}
	return r, err
}
開發者ID:DaGitNah,項目名稱:bitwrk,代碼行數:22,代碼來源:sell.go


注:本文中的github.com/indyjo/cafs.File.Open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。