瀏覽代碼

Merge pull request #25 from sbinet-staging/issue-24

lz4: guard Go-1.10 specific API behind build tags
Pierre Curto 7 年之前
父節點
當前提交
6b9367c9ff
共有 5 個文件被更改,包括 72 次插入28 次删除
  1. 12 2
      .travis.yml
  2. 2 0
      block_test.go
  3. 0 26
      lz4.go
  4. 29 0
      lz4_go1.10.go
  5. 29 0
      lz4_notgo1.10.go

+ 12 - 2
.travis.yml

@@ -1,8 +1,18 @@
 language: go
 
 go:
-  - 1.x
+  - 1.8.x
+  - 1.9.x
+  - 1.10.x
+  - master
+
+matrix:
+ fast_finish: true
+ allow_failures:
+   - go: master
+
+sudo: false
 
 script: 
  - go test -v -cpu=2
- - go test -v -cpu=2 -race
+ - go test -v -cpu=2 -race

+ 2 - 0
block_test.go

@@ -1,3 +1,5 @@
+//+build go1.9
+
 package lz4_test
 
 import (

+ 0 - 26
lz4.go

@@ -10,11 +10,6 @@
 //
 package lz4
 
-import (
-	"fmt"
-	"strings"
-)
-
 const (
 	// Extension is the LZ4 frame file name extension
 	Extension = ".lz4"
@@ -71,24 +66,3 @@ type Header struct {
 	CompressionLevel int    // Compression level (higher is better, use 0 for fastest compression).
 	done             bool   // Header processed flag (Read or Write and checked).
 }
-
-func (h Header) String() string {
-	var s strings.Builder
-
-	s.WriteString(fmt.Sprintf("%T{", h))
-	if h.BlockChecksum {
-		s.WriteString("BlockChecksum: true ")
-	}
-	if h.NoChecksum {
-		s.WriteString("NoChecksum: true ")
-	}
-	if bs := h.BlockMaxSize; bs != 0 && bs != 4<<20 {
-		s.WriteString(fmt.Sprintf("BlockMaxSize: %d ", bs))
-	}
-	if l := h.CompressionLevel; l != 0 {
-		s.WriteString(fmt.Sprintf("CompressionLevel: %d ", l))
-	}
-	s.WriteByte('}')
-
-	return s.String()
-}

+ 29 - 0
lz4_go1.10.go

@@ -0,0 +1,29 @@
+//+build go1.10
+
+package lz4
+
+import (
+	"fmt"
+	"strings"
+)
+
+func (h Header) String() string {
+	var s strings.Builder
+
+	s.WriteString(fmt.Sprintf("%T{", h))
+	if h.BlockChecksum {
+		s.WriteString("BlockChecksum: true ")
+	}
+	if h.NoChecksum {
+		s.WriteString("NoChecksum: true ")
+	}
+	if bs := h.BlockMaxSize; bs != 0 && bs != 4<<20 {
+		s.WriteString(fmt.Sprintf("BlockMaxSize: %d ", bs))
+	}
+	if l := h.CompressionLevel; l != 0 {
+		s.WriteString(fmt.Sprintf("CompressionLevel: %d ", l))
+	}
+	s.WriteByte('}')
+
+	return s.String()
+}

+ 29 - 0
lz4_notgo1.10.go

@@ -0,0 +1,29 @@
+//+build !go1.10
+
+package lz4
+
+import (
+	"bytes"
+	"fmt"
+)
+
+func (h Header) String() string {
+	var s bytes.Buffer
+
+	s.WriteString(fmt.Sprintf("%T{", h))
+	if h.BlockChecksum {
+		s.WriteString("BlockChecksum: true ")
+	}
+	if h.NoChecksum {
+		s.WriteString("NoChecksum: true ")
+	}
+	if bs := h.BlockMaxSize; bs != 0 && bs != 4<<20 {
+		s.WriteString(fmt.Sprintf("BlockMaxSize: %d ", bs))
+	}
+	if l := h.CompressionLevel; l != 0 {
+		s.WriteString(fmt.Sprintf("CompressionLevel: %d ", l))
+	}
+	s.WriteByte('}')
+
+	return s.String()
+}