示例#1
0
func TestSlicedAndConcatenated(t *testing.T) {
	f, err := os.Open("440hz.mp3")
	if err != nil {
		t.Fatalf("Error opening sample file: %v", err)
	}
	defer f.Close()

	slices, err := Slice(f, time.Second, 2*time.Second, 3*time.Second)
	if err != nil {
		t.Fatalf("Expected no error, got: %v", err)
	}

	concatenated := ioutil.NewMultiReadSeeker(slices...)

	l1, err := Length(f)
	if err != nil {
		t.Fatalf("Expected no error, got: %v", err)
	}
	l2, err := Length(concatenated)
	if err != nil {
		t.Fatalf("Expected no error, got: %v", err)
	}
	if l1 != l2 {
		t.Errorf("Expected concatenated (%v) to be the same length as original (%v)", l2, l1)
	}

}
示例#2
0
// Take a source MP3 and insert all the splice members into it (at the specified durations)
func Splice(src io.ReadSeeker, splice map[time.Duration]io.ReadSeeker) (*ioutil.MultiReadSeeker, error) {
	// Get the times
	spliceTimes := []time.Duration{}
	for k, _ := range splice {
		spliceTimes = append(spliceTimes, k)
	}
	sort.Sort(durationSorter(spliceTimes))

	// Slice up the src into len(splice)+1 pieces
	sliced, err := Slice(src, spliceTimes...)
	if err != nil {
		return nil, fmt.Errorf("error slicing src: %v", err)
	}

	// Insert splice members between the slices
	pieces := []io.ReadSeeker{sliced[0]}
	for i := 1; i < len(sliced); i++ {
		stripped, err := Stripped(splice[spliceTimes[i-1]])
		if err != nil {
			return nil, err
		}
		pieces = append(pieces, stripped, sliced[i])
	}

	// Treat all the pieces as one big ReadSeeker
	return ioutil.NewMultiReadSeeker(pieces...), nil
}
示例#3
0
文件: http.go 项目: ably-forks/flynn
func (api *httpAPI) ServeApplicationJS(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
	path := filepath.Join("app", "build", params.ByName("assetPath"))
	data, err := api.Asset(path)
	if err != nil {
		httphelper.Error(w, err)
		api.logger.Debug(err.Error())
		return
	}

	var jsConf bytes.Buffer
	jsConf.Write([]byte("window.InstallerConfig = "))
	json.NewEncoder(&jsConf).Encode(api.clientConfig)
	jsConf.Write([]byte(";\n"))

	r := ioutil.NewMultiReadSeeker(bytes.NewReader(jsConf.Bytes()), data)

	http.ServeContent(w, req, path, time.Now(), r)
}