Skip to content

Commit d36bad0

Browse files
authored
Merge pull request #64 from go-kivik/buffer-v3
Don't use Buffer constructer
2 parents c310983 + 90509f5 commit d36bad0

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,9 @@ pouchdb7:
5050
NODE_VER: 12
5151
NPM_PROFILE: pouchdb7-package.json
5252

53-
lint:
53+
linter:
5454
stage: test
55-
image: golang:1.13
56-
services: []
57-
before_script:
58-
- ''
55+
image: golangci/golangci-lint:v1.26
5956
script:
6057
- go mod download
61-
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.6
62-
- ./script/test_version.sh
6358
- golangci-lint run ./...

attachments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (d *db) GetAttachment(ctx context.Context, docID, filename string, opts map
3232

3333
func parseAttachment(obj *js.Object) (att *driver.Attachment, err error) {
3434
defer bindings.RecoverError(&err)
35-
if jsbuiltin.TypeOf(obj.Get("write")) == "function" {
35+
if jsbuiltin.TypeOf(obj.Get("write")) == jsbuiltin.TypeFunction {
3636
// This looks like a Buffer object; we're in Node.js
3737
body := obj.Call("toString", "binary").String()
3838
// It might make sense to wrap the Buffer itself in an io.Reader interface,

bindings/pouchdb.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func callBack(ctx context.Context, o caller, method string, args ...interface{})
100100

101101
// AllDBs returns the list of all existing (undeleted) databases.
102102
func (p *PouchDB) AllDBs(ctx context.Context) ([]string, error) {
103-
if jsbuiltin.TypeOf(p.Get("allDbs")) != "function" {
103+
if jsbuiltin.TypeOf(p.Get("allDbs")) != jsbuiltin.TypeFunction {
104104
return nil, errors.New("pouchdb-all-dbs plugin not loaded")
105105
}
106106
result, err := callBack(ctx, p, "allDbs")
@@ -290,8 +290,13 @@ func attachmentObject(contentType string, content io.Reader) (att *js.Object, er
290290
if _, err := buf.ReadFrom(content); err != nil {
291291
return nil, err
292292
}
293-
if buffer := js.Global.Get("Buffer"); jsbuiltin.TypeOf(buffer) == "function" {
293+
if buffer := js.Global.Get("Buffer"); jsbuiltin.TypeOf(buffer) == jsbuiltin.TypeFunction {
294294
// The Buffer type is supported, so we'll use that
295+
if jsbuiltin.TypeOf(buffer.Get("from")) == jsbuiltin.TypeFunction {
296+
// For newer versions of Node.js. See https://nodejs.org/fa/docs/guides/buffer-constructor-deprecation/
297+
return buffer.Call("from", buf.String()), nil
298+
}
299+
// Fall back to legacy Buffer constructor.
295300
return buffer.New(buf.String()), nil
296301
}
297302
if js.Global.Get("Blob") != js.Undefined {

0 commit comments

Comments
 (0)