nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: ember-cli/eslint-plugin-ember
Pull request #757 (2020-04-03 23:33:27)

Add tests that configs are exported and mentioned in the README


Patch:
diff --git a/lib/index.js b/lib/index.js
index 6acc8409..432ddd61 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -73,8 +73,8 @@ module.exports = {
   },
   configs: {
     base: require('./config/base'),
-    recommended: require('./config/recommended'),
     octane: require('./config/octane'),
+    recommended: require('./config/recommended'),
   },
   utils: {
     ember: require('./utils/ember'),


Test patch:
diff --git a/tests/config-setup.js b/tests/config-setup.js
new file mode 100644
index 00000000..b275cd72
--- /dev/null
+++ b/tests/config-setup.js
@@ -0,0 +1,29 @@
+'use strict';
+
+const { readdirSync, readFileSync } = require('fs');
+const { join } = require('path');
+const configs = require('../lib').configs;
+
+const CONFIG_NAMES = Object.keys(configs);
+
+describe('config setup is correct', function () {
+  it('should have a list of exported configs and config directory that match', function () {
+    const path = join(__dirname, '..', 'lib', 'config');
+    const files = readdirSync(path);
+
+    // eslint-disable-next-line jest/prefer-strict-equal
+    expect(CONFIG_NAMES).toEqual(
+      files.filter((file) => !file.startsWith('.')).map((file) => file.replace('.js', ''))
+    );
+  });
+
+  it('should mention all configs in the README', function () {
+    const path = join(__dirname, '..', 'README.md');
+    const file = readFileSync(path, 'utf8');
+
+    // We don't bother mentioning the `base` config in the README.
+    const CONFIG_NAMES_WITHOUT_BASE = CONFIG_NAMES.filter((configName) => configName !== 'base');
+
+    CONFIG_NAMES_WITHOUT_BASE.forEach((configName) => expect(file).toContain(configName));
+  });
+});
Repository: chanzuckerberg/fogg
Pull request #364 (2019-09-27 20:42:36)

update generated .travis.yml to have `dist: bionic`
Travis still defaults to ubuntu 16.

### Test Plan
* make test

### References
* https://docs.travis-ci.com/user/reference/overview/


codecov[bot]: # [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/364?src=pr&el=h1) Report
> Merging [#364](https://codecov.io/gh/chanzuckerberg/fogg/pull/364?src=pr&el=desc) into [master](https://codecov.io/gh/chanzuckerberg/fogg/commit/ec44897efb56dd3a6ef22b842f6e0ee99c111ec5?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/chanzuckerberg/fogg/pull/364/graphs/tree.svg?width=650&token=57DhtZ7g2A&height=150&src=pr)](https://codecov.io/gh/chanzuckerberg/fogg/pull/364?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #364   +/-   ##
=======================================
  Coverage   77.74%   77.74%           
=======================================
  Files          25       25           
  Lines        1896     1896           
=======================================
  Hits         1474     1474           
  Misses        285      285           
  Partials      137      137
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/364?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/364?src=pr&el=footer). Last update [ec44897...6c6d125](https://codecov.io/gh/chanzuckerberg/fogg/pull/364?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/templates/travis-ci/.travis.yml.tmpl b/templates/travis-ci/.travis.yml.tmpl
index fb6d3f17..2ed39aa3 100644
--- a/templates/travis-ci/.travis.yml.tmpl
+++ b/templates/travis-ci/.travis.yml.tmpl
@@ -1,5 +1,6 @@
 # Auto-generated by fogg. Do not edit
 # Make improvements in fogg, so that everyone can benefit.
+dist: bionic
 language: python
 sudo: required
 python: 3.6


Test patch:
diff --git a/testdata/v1_full/.travis.yml b/testdata/v1_full/.travis.yml
index 7d37f002..38db1fad 100644
--- a/testdata/v1_full/.travis.yml
+++ b/testdata/v1_full/.travis.yml
@@ -1,5 +1,6 @@
 # Auto-generated by fogg. Do not edit
 # Make improvements in fogg, so that everyone can benefit.
+dist: bionic
 language: python
 sudo: required
 python: 3.6
Repository: chanzuckerberg/fogg
Pull request #404 (2020-02-11 19:25:15)

[fix] remove deprecated sudo command from travis configuartion
### Summary
sudo keyword is fully deprecated in travis CI.  made changes to remove it from the travis configuration file.

### Test Plan
ran make test locally



codecov[bot]: # [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/404?src=pr&el=h1) Report
> Merging [#404](https://codecov.io/gh/chanzuckerberg/fogg/pull/404?src=pr&el=desc) into [master](https://codecov.io/gh/chanzuckerberg/fogg/commit/3f82c59633d18d2db985cfe962f14928cca80ea4&el=desc) will **not change** coverage by `%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/chanzuckerberg/fogg/pull/404/graphs/tree.svg?width=650&height=150&src=pr&token=57DhtZ7g2A)](https://codecov.io/gh/chanzuckerberg/fogg/pull/404?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #404   +/-   ##
=======================================
  Coverage   78.15%   78.15%           
=======================================
  Files          24       24           
  Lines        1909     1909           
=======================================
  Hits         1492     1492           
  Misses        276      276           
  Partials      141      141           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/404?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/404?src=pr&el=footer). Last update [3f82c59...31844f0](https://codecov.io/gh/chanzuckerberg/fogg/pull/404?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/.travis.yml b/.travis.yml
index 2578cb6b..272ed8b1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,5 @@
 dist: bionic
 language: go
-sudo: false
 go:
   - "1.13.1"
 env:
diff --git a/templates/travis-ci/.travis.yml.tmpl b/templates/travis-ci/.travis.yml.tmpl
index f84251d9..1548a282 100644
--- a/templates/travis-ci/.travis.yml.tmpl
+++ b/templates/travis-ci/.travis.yml.tmpl
@@ -3,7 +3,6 @@
 # Make improvements in fogg, so that everyone can benefit.
 dist: bionic
 language: python
-sudo: required
 python: 3.6
 env:
   global:


Test patch:
diff --git a/testdata/v1_full/.travis.yml b/testdata/v1_full/.travis.yml
index 2c46468d..c19bdb07 100644
--- a/testdata/v1_full/.travis.yml
+++ b/testdata/v1_full/.travis.yml
@@ -3,7 +3,6 @@
 # Make improvements in fogg, so that everyone can benefit.
 dist: bionic
 language: python
-sudo: required
 python: 3.6
 env:
   global:
Repository: hamba/avro
Pull request #5 (2019-04-02 08:16:12)

Fix issue with typed union in record


Patch:
diff --git a/codec_union.go b/codec_union.go
index 9a555dc..dc3ae03 100644
--- a/codec_union.go
+++ b/codec_union.go
@@ -163,6 +163,10 @@ type unionTypedDecoder struct {
 }
 
 func (d *unionTypedDecoder) Decode(ptr unsafe.Pointer, r *Reader) {
+	if *((*unsafe.Pointer)(ptr)) == nil {
+		newPtr := d.typ.UnsafeNew()
+		*((*unsafe.Pointer)(ptr)) = newPtr
+	}
 	union := d.typ.UnsafeIndirect(ptr).(UnionType)
 
 	schema := getUnionSchema(d.schema, r)


Test patch:
diff --git a/decoder_union_test.go b/decoder_union_test.go
index 2869103..a5c030b 100644
--- a/decoder_union_test.go
+++ b/decoder_union_test.go
@@ -104,6 +104,26 @@ func TestDecoder_UnionTyped(t *testing.T) {
 	assert.Equal(t, 27, got.Val)
 }
 
+func TestDecoder_UnionTypedInRecord(t *testing.T) {
+	defer ConfigTeardown()
+
+	data := []byte{0x02, 0x36}
+	schema := `{
+	"type": "record",
+	"name": "test",
+	"fields" : [
+		{"name": "a", "type": ["null", "int"]}
+	]
+}`
+	dec, _ := avro.NewDecoder(schema, bytes.NewReader(data))
+
+	got := &TestUnionRecord{}
+	err := dec.Decode(&got)
+
+	assert.NoError(t, err)
+	assert.Equal(t, 27, got.A.Val)
+}
+
 func TestDecoder_UnionTypedNull(t *testing.T) {
 	defer ConfigTeardown()
 
diff --git a/types_test.go b/types_test.go
index 2c51208..1252bb2 100644
--- a/types_test.go
+++ b/types_test.go
@@ -28,6 +28,10 @@ type TestNestedRecord struct {
 	B TestRecord `avro:"b"`
 }
 
+type TestUnionRecord struct {
+	A *TestUnionType `avro:"a"`
+}
+
 type TestUnionType struct {
 	Val interface{}
 }
Repository: hamba/avro
Pull request #11 (2019-04-23 16:38:04)

Fixed issue with registry error


Patch:
diff --git a/registry/client.go b/registry/client.go
index d5cac14..7fe6e73 100644
--- a/registry/client.go
+++ b/registry/client.go
@@ -218,7 +218,7 @@ func (c *Client) request(method, uri string, in, out interface{}) error {
 
 	if resp.StatusCode >= 400 {
 		err := Error{StatusCode: resp.StatusCode}
-		jsoniter.NewDecoder(resp.Body).Decode(err)
+		_ = jsoniter.NewDecoder(resp.Body).Decode(&err)
 		return err
 	}
 
@@ -235,5 +235,9 @@ type Error struct {
 
 // Error returns the error message.
 func (e Error) Error() string {
-	return e.Message
+	if e.Message != "" {
+		return e.Message
+	}
+
+	return "registry error: " + strconv.Itoa(e.StatusCode)
 }


Test patch:
diff --git a/registry/client_test.go b/registry/client_test.go
index a643f5a..f509b70 100644
--- a/registry/client_test.go
+++ b/registry/client_test.go
@@ -22,6 +22,26 @@ func TestNewClient_UrlError(t *testing.T) {
 	assert.Error(t, err)
 }
 
+func TestClient_PopulatesError(t *testing.T) {
+	s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		w.Header().Add("Content-Type", "application/vnd.schemaregistry.v1+json")
+		w.WriteHeader(422)
+		_, _ = w.Write([]byte(`{"error_code": 42202, "message": "schema may not be empty"}"`))
+	}))
+	defer s.Close()
+	client, _ := registry.NewClient(s.URL)
+
+	_, _, err := client.CreateSchema("test", "")
+
+	assert.Error(t, err)
+	assert.IsType(t, registry.Error{}, err)
+	assert.Equal(t, "schema may not be empty", err.Error())
+	regError := err.(registry.Error)
+	assert.Equal(t, 422, regError.StatusCode)
+	assert.Equal(t, 42202, regError.Code)
+	assert.Equal(t, "schema may not be empty", regError.Message)
+}
+
 func TestClient_GetSchema(t *testing.T) {
 	s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		assert.Equal(t, "GET", r.Method)
@@ -403,3 +423,13 @@ func TestError_Error(t *testing.T) {
 
 	assert.Equal(t, "Schema not found", str)
 }
+
+func TestError_ErrorEmptyMEssage(t *testing.T) {
+	err := registry.Error{
+		StatusCode: 404,
+	}
+
+	str := err.Error()
+
+	assert.Equal(t, "registry error: 404", str)
+}
Repository: hamba/avro
Pull request #21 (2019-07-30 19:03:15)

Small speed improvement


Patch:
diff --git a/codec_record.go b/codec_record.go
index 4aa024a..06ce3a1 100644
--- a/codec_record.go
+++ b/codec_record.go
@@ -91,7 +91,7 @@ func (d *structDecoder) Decode(ptr unsafe.Pointer, r *Reader) {
 }
 
 type structFieldDecoder struct {
-	field   reflect2.StructField
+	field   *reflect2.UnsafeStructField
 	decoder ValDecoder
 }
 
@@ -321,7 +321,7 @@ func (sf structFields) Get(name string) *structField {
 }
 
 type structField struct {
-	Field reflect2.StructField
+	Field *reflect2.UnsafeStructField
 	Name  string
 }
 
@@ -329,7 +329,7 @@ func describeStruct(tagKey string, typ reflect2.Type) *structDescriptor {
 	structType := typ.(*reflect2.UnsafeStructType)
 	fields := structFields{}
 	for i := 0; i < structType.NumField(); i++ {
-		field := structType.Field(i)
+		field := structType.Field(i).(*reflect2.UnsafeStructField)
 		fieldName := field.Name()
 		if tag, ok := field.Tag().Lookup(tagKey); ok {
 			fieldName = tag
diff --git a/go.sum b/go.sum
index a577353..086b852 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,6 @@
 github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
 github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=


Test patch:
diff --git a/reader_test.go b/reader_test.go
index a30096a..14b90f8 100644
--- a/reader_test.go
+++ b/reader_test.go
@@ -579,6 +579,18 @@ func TestReader_ReadString(t *testing.T) {
 	}
 }
 
+func TestReader_ReadStringFastPathIsntBoundToBuffer(t *testing.T) {
+	data := []byte{0x06, 0x66, 0x6F, 0x6F, 0x08, 0x61, 0x76, 0x72, 0x6F}
+	r := avro.NewReader(bytes.NewReader(data), 4)
+
+	got1 := r.ReadString()
+	got2 := r.ReadString()
+
+	assert.NoError(t, r.Error)
+	assert.Equal(t, "foo", got1)
+	assert.Equal(t, "avro", got2)
+}
+
 func TestReader_ReadBlockHeader(t *testing.T) {
 	tests := []struct {
 		data []byte
Repository: hamba/avro
Pull request #39 (2020-02-28 17:47:18)

Add OCF metadata
* Added OCF decoder metadata retrieval
* Added OCF encoder metadata setting

nrwiersma: Fixes #32 

Patch:
diff --git a/ocf/ocf.go b/ocf/ocf.go
index 166190b..6106078 100644
--- a/ocf/ocf.go
+++ b/ocf/ocf.go
@@ -47,6 +47,7 @@ type Decoder struct {
 	reader      *avro.Reader
 	resetReader *bytesx.ResetReader
 	decoder     *avro.Decoder
+	meta        map[string][]byte
 	sync        [16]byte
 
 	codec Codec
@@ -83,11 +84,17 @@ func NewDecoder(r io.Reader) (*Decoder, error) {
 		reader:      reader,
 		resetReader: decReader,
 		decoder:     avro.NewDecoderForSchema(schema, decReader),
+		meta:        h.Meta,
 		sync:        h.Sync,
 		codec:       codec,
 	}, nil
 }
 
+// Metadata returns the header metadata.
+func (d *Decoder) Metadata() map[string][]byte {
+	return d.meta
+}
+
 // HasNext determines if there is another value to read.
 func (d *Decoder) HasNext() bool {
 	if d.count <= 0 {
@@ -150,6 +157,7 @@ func (d *Decoder) readBlock() int64 {
 type encoderConfig struct {
 	BlockLength int
 	CodecName   CodecName
+	Metadata    map[string][]byte
 }
 
 // EncoderFunc represents an configuration function for Encoder
@@ -169,6 +177,13 @@ func WithCodec(codec CodecName) EncoderFunc {
 	}
 }
 
+// WithMetadata sets the metadata on the encoder header.
+func WithMetadata(meta map[string][]byte) EncoderFunc {
+	return func(cfg *encoderConfig) {
+		cfg.Metadata = meta
+	}
+}
+
 // Encoder writes Avro container file to an output stream.
 type Encoder struct {
 	writer  *avro.Writer
@@ -192,6 +207,7 @@ func NewEncoder(s string, w io.Writer, opts ...EncoderFunc) (*Encoder, error) {
 	cfg := encoderConfig{
 		BlockLength: 100,
 		CodecName:   Null,
+		Metadata:    map[string][]byte{},
 	}
 	for _, opt := range opts {
 		opt(&cfg)
@@ -199,12 +215,11 @@ func NewEncoder(s string, w io.Writer, opts ...EncoderFunc) (*Encoder, error) {
 
 	writer := avro.NewWriter(w, 512)
 
+	cfg.Metadata[schemaKey] = []byte(schema.String())
+	cfg.Metadata[codecKey] = []byte(cfg.CodecName)
 	header := Header{
 		Magic: magicBytes,
-		Meta: map[string][]byte{
-			schemaKey: []byte(schema.String()),
-			codecKey:  []byte(cfg.CodecName),
-		},
+		Meta:  cfg.Metadata,
 	}
 	_, _ = rand.Read(header.Sync[:])
 	writer.WriteVal(HeaderSchema, header)


Test patch:
diff --git a/ocf/ocf_test.go b/ocf/ocf_test.go
index 26fa728..d7b2392 100644
--- a/ocf/ocf_test.go
+++ b/ocf/ocf_test.go
@@ -538,6 +538,23 @@ func TestEncoder_CloseHandlesWriteBlockError(t *testing.T) {
 	assert.Error(t, err)
 }
 
+func TestEncodeDecodeMetadata(t *testing.T) {
+	buf := &bytes.Buffer{}
+	enc, _ := ocf.NewEncoder(`"long"`, buf, ocf.WithMetadata(map[string][]byte{
+		"test": []byte("foo"),
+	}))
+
+	err := enc.Encode(int64(1))
+	assert.NoError(t, err)
+
+	enc.Close()
+
+	dec, err := ocf.NewDecoder(buf)
+	assert.NoError(t, err)
+
+	assert.Equal(t, []byte("foo"), dec.Metadata()["test"])
+}
+
 type errorWriter struct{}
 
 func (*errorWriter) Write(p []byte) (n int, err error) {
Repository: hamba/avro
Pull request #54 (2020-07-20 09:22:55)

Register a boolean type
This commit fixes the following error that occurs with a map including a boolean type in unions.

```go
package main

import (
	"bytes"
	"encoding/json"
	"log"

	"github.com/hamba/avro"
)

var Schema = `{
		"type": "record",
		"name": "simple",
		"namespace": "org.hamba.avro",
		"fields" : [
			{
				"name": "properties",
				"type": {
					"type": "map",
					"values": ["null", "boolean"]
				}
			}
		]
	}`

type SimpleRecord struct {
	Properties map[string]interface{} `avro:"properties"`
}

func main() {
	schema, err := avro.Parse(Schema)
	if err != nil {
		log.Fatal(err)
	}

	data := []byte(`
	{
		"properties": {
			"bool": true
		}
	}
	`)

	in := SimpleRecord{}

	buffer := bytes.NewReader(data)
	decoder := json.NewDecoder(buffer)

	err = decoder.Decode(&in)
	if err != nil {
		log.Fatal(err)
	}

	_, err = avro.Marshal(schema, in)
	if err != nil {
		log.Fatal(err)
	}
}

```

error

```
2020/07/20 18:21:14 Properties: map[string]interface {}: avro: unable to resolve type bool
```


Patch:
diff --git a/resolver.go b/resolver.go
index e3441ee..f3e4983 100644
--- a/resolver.go
+++ b/resolver.go
@@ -32,6 +32,7 @@ func NewTypeResolver() *TypeResolver {
 	r.Register(string(Double), float64(0))
 	r.Register(string(String), "")
 	r.Register(string(Bytes), []byte{})
+	r.Register(string(Boolean), bool(true))
 
 	return r
 }


Test patch:
diff --git a/decoder_union_test.go b/decoder_union_test.go
index 400b2c7..85ad3d4 100644
--- a/decoder_union_test.go
+++ b/decoder_union_test.go
@@ -242,6 +242,20 @@ func TestDecoder_UnionInterfaceInMap(t *testing.T) {
 	assert.Equal(t, map[string]interface{}{"foo": 27}, got)
 }
 
+func TestDecoder_UnionInterfaceInMapWithBool(t *testing.T) {
+	defer ConfigTeardown()
+
+	data := []byte{0x01, 0x0c, 0x06, 0x66, 0x6F, 0x6F, 0x02, 0x01, 0x00}
+	schema := `{"type":"map", "values": ["null", "boolean"]}`
+	dec, _ := avro.NewDecoder(schema, bytes.NewReader(data))
+
+	var got map[string]interface{}
+	err := dec.Decode(&got)
+
+	assert.NoError(t, err)
+	assert.Equal(t, map[string]interface{}{"foo": true}, got)
+}
+
 func TestDecoder_UnionInterfaceMap(t *testing.T) {
 	defer ConfigTeardown()
 
diff --git a/encoder_union_test.go b/encoder_union_test.go
index 69cc083..9126d79 100644
--- a/encoder_union_test.go
+++ b/encoder_union_test.go
@@ -230,6 +230,20 @@ func TestEncoder_UnionInterfaceMap(t *testing.T) {
 	assert.Equal(t, []byte{0x02, 0x01, 0x0a, 0x06, 0x66, 0x6f, 0x6f, 0x36, 0x00}, buf.Bytes())
 }
 
+func TestEncoder_UnionInterfaceInMapWithBool(t *testing.T) {
+	defer ConfigTeardown()
+
+	schema := `{"type":"map", "values": ["null", "boolean"]}`
+	buf := bytes.NewBuffer([]byte{})
+	enc, err := avro.NewEncoder(schema, buf)
+	assert.NoError(t, err)
+
+	err = enc.Encode(map[string]interface{}{"foo": true})
+
+	assert.NoError(t, err)
+	assert.Equal(t, []byte{0x01, 0x0c, 0x06, 0x66, 0x6F, 0x6F, 0x02, 0x01, 0x00}, buf.Bytes())
+}
+
 func TestEncoder_UnionInterfaceArray(t *testing.T) {
 	defer ConfigTeardown()
Repository: hamba/avro
Pull request #63 (2020-08-24 11:11:15)

ocf: add encoder Flush()
It seems that encoder.Close() does not close anything, but it just flushes
the block, i added Flush() kept Close() but added a deprecation note.

nrwiersma: The use of `Close` here is intentional. As we are given an `io.Writer` and not a `io.WriteCloser` there is nothing for us to close as such (but it is more extensible), but what we are doing is implementing `io.Closer` which is natural to test and run should it be implemented. The same pattern can be seen for instance in `encoding/base64` and other encoders where.

I am not opposed to adding `Flush` and having `Close` call flush, although I am not sure how much value that brings, but IMO the `Encoder` must implement `io.Closer`.
yields: > I am not opposed to adding `Flush` and having `Close` call flush, although I am not sure how much value that brings, but IMO the `Encoder` must implement `io.Closer`.

The main value it brings is when you need to read messages off a queue, write them to an avro file and you want to fsync before you ack this batch of messages.

The file writer is `*ocf.Encoder -> *bufio.Writer -> *os.File`, on an interval we flush all those buffers, fsync the file and finally commit all the offsets to Kafka. It feels wrong to call `*ocf.Encoder.Close()` when flushing the file, even though I know that this method doesn't close any resource.

How about I remove the deprecation note from `Close()`?

Thanks for the super quick response btw! :)
nrwiersma: Yes, that seems good to me.
yields: Sweet, pushed the changes, changed the commit message too.

Patch:
diff --git a/ocf/ocf.go b/ocf/ocf.go
index b85a1f7..5242237 100644
--- a/ocf/ocf.go
+++ b/ocf/ocf.go
@@ -259,8 +259,8 @@ func (e *Encoder) Encode(v interface{}) error {
 	return e.writer.Error
 }
 
-// Close closes the encoder, flushing the writer.
-func (e *Encoder) Close() error {
+// Flush flushes the underlying writer.
+func (e *Encoder) Flush() error {
 	if e.count == 0 {
 		return nil
 	}
@@ -272,6 +272,11 @@ func (e *Encoder) Close() error {
 	return e.writer.Error
 }
 
+// Close closes the encoder, flushing the writer.
+func (e *Encoder) Close() error {
+	return e.Flush()
+}
+
 func (e *Encoder) writerBlock() error {
 	e.writer.WriteLong(int64(e.count))
 


Test patch:
diff --git a/ocf/example_test.go b/ocf/example_test.go
index e606887..3f5c861 100644
--- a/ocf/example_test.go
+++ b/ocf/example_test.go
@@ -72,7 +72,11 @@ func ExampleNewEncoder() {
 		log.Fatal(err)
 	}
 
-	if err := enc.Close(); err != nil {
+	if err := enc.Flush(); err != nil {
+		log.Fatal(err)
+	}
+
+	if err := f.Sync(); err != nil {
 		log.Fatal(err)
 	}
 }
Repository: hamba/avro
Pull request #144 (2022-01-24 12:16:18)

ocf Encoder should implement writer interface
As mentioned in #142, the Write method should conform to the `io.Writer` interface

Signed-off-by: Jonas Brunsgaard <jonas.brunsgaard@gmail.com>


Patch:
diff --git a/ocf/ocf.go b/ocf/ocf.go
index a585b9a..e40591d 100644
--- a/ocf/ocf.go
+++ b/ocf/ocf.go
@@ -247,19 +247,20 @@ func NewEncoder(s string, w io.Writer, opts ...EncoderFunc) (*Encoder, error) {
 // therefore the caller is responsible for encoding the bytes. No error will be
 // thrown if the bytes does not conform to the schema given to NewEncoder, but
 // the final ocf data will be corrupted.
-func (e *Encoder) Write(v []byte) error {
-	if _, err := e.buf.Write(v); err != nil {
-		return err
+func (e *Encoder) Write(p []byte) (n int, err error) {
+	n, err = e.buf.Write(p)
+	if err != nil {
+		return n, err
 	}
 
 	e.count++
 	if e.count >= e.blockLength {
 		if err := e.writerBlock(); err != nil {
-			return err
+			return n, err
 		}
 	}
 
-	return e.writer.Error
+	return n, e.writer.Error
 }
 
 // Encode writes the Avro encoding of v to the stream.


Test patch:
diff --git a/ocf/ocf_test.go b/ocf/ocf_test.go
index b12a608..1431e44 100644
--- a/ocf/ocf_test.go
+++ b/ocf/ocf_test.go
@@ -457,12 +457,13 @@ func TestEncoder_Write(t *testing.T) {
 	encodedBytes, err := avro.Marshal(avro.MustParse(schema), record)
 	require.NoError(t, err)
 
-	err = enc.Write(encodedBytes)
+	n, err := enc.Write(encodedBytes)
 	require.NoError(t, err)
 
 	err = enc.Close()
 	require.NoError(t, err)
 
+	require.Equal(t, n, len(encodedBytes))
 	require.Equal(t, 957, buf.Len())
 }