A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/isomorphic-git/isomorphic-git/commit/2c1e26f9a02bb800eca07bada6c25c01b41c66e7 below:

return Uint8Arrays instead of Buffers (#1009) · isomorphic-git/isomorphic-git@2c1e26f · GitHub

File tree Expand file treeCollapse file tree 19 files changed

+79

-77

lines changed

Filter options

Expand file treeCollapse file tree 19 files changed

+79

-77

lines changed Original file line number Diff line number Diff line change

@@ -49,7 +49,7 @@ At the time of writing, the following breaking changes are planned:

49 49

- [ ] The `fs` and `emitter` function arguments will be removed.

50 50

- [x] The `fast` argument to `pull` will be removed since it will always use the `fastCheckout` implementation.

51 51

- [x] The `signing` function argument of `log` will be removed, and `log` will simply always return a payload. **Update: Actually, it now returns the same kind of objects as `readCommit` because that just makes a lot of sense.** (This change is to simplify the type signature of `log` so we don't need function overloading; it is the only thing blocking me from abandoning the hand-crafted `index.d.ts` file and generating the TypeScript definitions directly from the JSDoc tags that already power the website docs.)

52 -

- [ ] Any functions that currently return `Buffer` objects will instead return `Uint8Array` so we can eventually drop the bloated Buffer browser polyfill.

52 +

- [x] Any functions that currently return `Buffer` objects will instead return `Uint8Array` so we can eventually drop the bloated Buffer browser polyfill.

53 53

- [x] The `pattern` and globbing options will be removed from `statusMatrix` so we can drop the dependencies on `globalyzer` and `globrex`, but you'll be able to bring your own `filter` function instead.

54 54

- [x] The `autoTranslateSSH` feature will be removed, since it's trivial to implement using just the `UnknownTransportError.data.suggestion`

55 55

- [ ] The `internal-apis` will be excluded from `dist` before publishing. Because those are only exposed so I could unit test them and no one should be using them lol.

Original file line number Diff line number Diff line change

@@ -27,7 +27,9 @@ describe('addNote', () => {

27 27

oid: '3b4b7a6c2382ea60a0b4c7ff69920af9a2e6408d',

28 28

filepath: 'f6d51b1f9a449079f6999be1fb249c359511f164'

29 29

})

30 -

expect(blob.toString('utf8')).toEqual('This is a note about a commit.')

30 +

expect(Buffer.from(blob).toString('utf8')).toEqual(

31 +

'This is a note about a commit.'

32 +

)

31 33

})

32 34

it('to a tree', async () => {

33 35

// Setup

@@ -52,7 +54,9 @@ describe('addNote', () => {

52 54

oid: '4b52ff827d2b5fe1786bf52a1b78dd25517b6cdd',

53 55

filepath: '199948939a0b95c6f27668689102496574b2c332'

54 56

})

55 -

expect(blob.toString('utf8')).toEqual('This is a note about a tree.')

57 +

expect(Buffer.from(blob).toString('utf8')).toEqual(

58 +

'This is a note about a tree.'

59 +

)

56 60

})

57 61

it('to a blob', async () => {

58 62

// Setup

@@ -77,7 +81,9 @@ describe('addNote', () => {

77 81

oid: '6428616e2600d3cd4b66059d5c561a85ce4b33ff',

78 82

filepath: '68aba62e560c0ebc3396e8ae9335232cd93a3f60'

79 83

})

80 -

expect(blob.toString('utf8')).toEqual('This is a note about a blob.')

84 +

expect(Buffer.from(blob).toString('utf8')).toEqual(

85 +

'This is a note about a blob.'

86 +

)

81 87

})

82 88

it('consecutive notes accumulate', async () => {

83 89

// Setup

@@ -153,7 +159,9 @@ describe('addNote', () => {

153 159

oid: '6428616e2600d3cd4b66059d5c561a85ce4b33ff',

154 160

filepath: '68aba62e560c0ebc3396e8ae9335232cd93a3f60'

155 161

})

156 -

expect(blob.toString('utf8')).toEqual('This is a note about a blob.')

162 +

expect(Buffer.from(blob).toString('utf8')).toEqual(

163 +

'This is a note about a blob.'

164 +

)

157 165

})

158 166

it('throws if note already exists', async () => {

159 167

// Setup

@@ -221,7 +229,7 @@ describe('addNote', () => {

221 229

oid,

222 230

filepath: 'f6d51b1f9a449079f6999be1fb249c359511f164'

223 231

})

224 -

expect(blob.toString('utf8')).toEqual(

232 +

expect(Buffer.from(blob).toString('utf8')).toEqual(

225 233

'This is the newer note about a commit.'

226 234

)

227 235

})

Original file line number Diff line number Diff line change

@@ -39,14 +39,14 @@ const wrapped = Buffer.concat([

39 39

])

40 40 41 41

describe('hashBlob', () => {

42 -

it('object as Buffer', async () => {

42 +

it('object as Uint8Array', async () => {

43 43

// Test

44 44

const { oid, object, format } = await hashBlob({

45 45

object: buffer

46 46

})

47 47

expect(oid).toEqual('4551a1856279dde6ae9d65862a1dff59a5f199d8')

48 48

expect(format).toEqual('wrapped')

49 -

expect(Buffer.compare(object, wrapped) === 0).toBe(true)

49 +

expect(Buffer.compare(Buffer.from(object), wrapped) === 0).toBe(true)

50 50

})

51 51 52 52

it('object as String', async () => {

@@ -56,6 +56,6 @@ describe('hashBlob', () => {

56 56

})

57 57

expect(oid).toEqual('4551a1856279dde6ae9d65862a1dff59a5f199d8')

58 58

expect(format).toEqual('wrapped')

59 -

expect(Buffer.compare(object, wrapped) === 0).toBe(true)

59 +

expect(Buffer.compare(Buffer.from(object), wrapped) === 0).toBe(true)

60 60

})

61 61

})

Original file line number Diff line number Diff line change

@@ -32,6 +32,9 @@ describe('packObjects', () => {

32 32

})

33 33

expect(filename).toBe('pack-76178ca22ef818f971fca371d84bce571d474b1d.pack')

34 34

expect(fixture.buffer).toEqual(packfile.buffer)

35 +

expect(

36 +

Buffer.compare(Buffer.from(fixture), Buffer.from(packfile)) === 0

37 +

).toBe(true)

35 38

expect(await fs.exists(path.join(gitdir, `objects/pack/${filename}`))).toBe(

36 39

false

37 40

)

@@ -67,5 +70,8 @@ describe('packObjects', () => {

67 70

expect(await fs.exists(filepath)).toBe(true)

68 71

const packfile = await fs.read(filepath)

69 72

expect(fixture.buffer).toEqual(packfile.buffer)

73 +

expect(

74 +

Buffer.compare(Buffer.from(fixture), Buffer.from(packfile)) === 0

75 +

).toBe(true)

70 76

})

71 77

})

Original file line number Diff line number Diff line change

@@ -34,7 +34,7 @@ describe('readBlob', () => {

34 34

gitdir,

35 35

oid: '4551a1856279dde6ae9d65862a1dff59a5f199d8'

36 36

})

37 -

expect(blob.toString('utf8')).toMatchSnapshot()

37 +

expect(Buffer.from(blob).toString('utf8')).toMatchSnapshot()

38 38

})

39 39

it('peels tags', async () => {

40 40

// Setup

@@ -56,7 +56,7 @@ describe('readBlob', () => {

56 56

filepath: 'cli.js'

57 57

})

58 58

expect(oid).toEqual('4551a1856279dde6ae9d65862a1dff59a5f199d8')

59 -

expect(blob.toString('hex')).toMatchSnapshot()

59 +

expect(Buffer.from(blob).toString('hex')).toMatchSnapshot()

60 60

})

61 61

it('with deep filepath to blob', async () => {

62 62

// Setup

@@ -68,7 +68,7 @@ describe('readBlob', () => {

68 68

filepath: 'src/commands/clone.js'

69 69

})

70 70

expect(oid).toEqual('5264f23285d8be3ce45f95c102001ffa1d5391d3')

71 -

expect(blob.toString('hex')).toMatchSnapshot()

71 +

expect(Buffer.from(blob).toString('hex')).toMatchSnapshot()

72 72

})

73 73

it('with simple filepath to tree', async () => {

74 74

// Setup

Original file line number Diff line number Diff line change

@@ -12,7 +12,9 @@ describe('readNote', () => {

12 12

gitdir,

13 13

oid: 'f6d51b1f9a449079f6999be1fb249c359511f164'

14 14

})

15 -

expect(note.toString('utf8')).toEqual('This is a note about a commit.\n')

15 +

expect(Buffer.from(note).toString('utf8')).toEqual(

16 +

'This is a note about a commit.\n'

17 +

)

16 18

})

17 19

it('to a tree', async () => {

18 20

// Setup

@@ -22,7 +24,9 @@ describe('readNote', () => {

22 24

gitdir,

23 25

oid: '199948939a0b95c6f27668689102496574b2c332'

24 26

})

25 -

expect(note.toString('utf8')).toEqual('This is a note about a tree.\n')

27 +

expect(Buffer.from(note).toString('utf8')).toEqual(

28 +

'This is a note about a tree.\n'

29 +

)

26 30

})

27 31

it('to a blob', async () => {

28 32

// Setup

@@ -32,7 +36,9 @@ describe('readNote', () => {

32 36

gitdir,

33 37

oid: '68aba62e560c0ebc3396e8ae9335232cd93a3f60'

34 38

})

35 -

expect(note.toString('utf8')).toEqual('This is a note about a blob.\n')

39 +

expect(Buffer.from(note).toString('utf8')).toEqual(

40 +

'This is a note about a blob.\n'

41 +

)

36 42

})

37 43

it('from an alternate branch', async () => {

38 44

// Setup

@@ -43,7 +49,7 @@ describe('readNote', () => {

43 49

ref: 'refs/notes/alt',

44 50

oid: 'f6d51b1f9a449079f6999be1fb249c359511f164'

45 51

})

46 -

expect(note.toString('utf8')).toEqual(

52 +

expect(Buffer.from(note).toString('utf8')).toEqual(

47 53

'This is alternate note about a commit.\n'

48 54

)

49 55

})

Original file line number Diff line number Diff line change

@@ -50,7 +50,7 @@ describe('readObject', () => {

50 50

expect(ref.format).toEqual('content')

51 51

expect(ref.type).toEqual('commit')

52 52

expect(ref.source).toBe('objects/e1/0ebb90d03eaacca84de1af0a59b444232da99e')

53 -

expect(ref.object.toString('hex')).toMatchSnapshot()

53 +

expect(Buffer.from(ref.object).toString('hex')).toMatchSnapshot()

54 54

})

55 55

it('wrapped', async () => {

56 56

// Setup

@@ -64,7 +64,7 @@ describe('readObject', () => {

64 64

expect(ref.format).toEqual('wrapped')

65 65

expect(ref.type).toEqual(undefined)

66 66

expect(ref.source).toBe('objects/e1/0ebb90d03eaacca84de1af0a59b444232da99e')

67 -

expect(ref.object.toString('hex')).toMatchSnapshot()

67 +

expect(Buffer.from(ref.object).toString('hex')).toMatchSnapshot()

68 68

})

69 69

it('deflated', async () => {

70 70

// Setup

@@ -78,7 +78,7 @@ describe('readObject', () => {

78 78

expect(ref.format).toEqual('deflated')

79 79

expect(ref.type).toEqual(undefined)

80 80

expect(ref.source).toBe('objects/e1/0ebb90d03eaacca84de1af0a59b444232da99e')

81 -

expect(ref.object.toString('hex')).toMatchSnapshot()

81 +

expect(Buffer.from(ref.object).toString('hex')).toMatchSnapshot()

82 82

})

83 83

it('from packfile', async () => {

84 84

// Setup

@@ -94,7 +94,7 @@ describe('readObject', () => {

94 94

expect(ref.source).toBe(

95 95

'objects/pack/pack-1a1e70d2f116e8cb0cb42d26019e5c7d0eb01888.pack'

96 96

)

97 -

expect(ref.object.toString('hex')).toMatchSnapshot()

97 +

expect(Buffer.from(ref.object).toString('hex')).toMatchSnapshot()

98 98

})

99 99

it('blob with encoding', async () => {

100 100

// Setup

@@ -129,7 +129,7 @@ describe('readObject', () => {

129 129

'objects/pack/pack-1a1e70d2f116e8cb0cb42d26019e5c7d0eb01888.pack'

130 130

)

131 131

expect(ref.oid).toEqual('4551a1856279dde6ae9d65862a1dff59a5f199d8')

132 -

expect(ref.object.toString('hex')).toMatchSnapshot()

132 +

expect(Buffer.from(ref.object).toString('hex')).toMatchSnapshot()

133 133

})

134 134

it('with deep filepath to blob', async () => {

135 135

// Setup

@@ -144,7 +144,7 @@ describe('readObject', () => {

144 144

expect(ref.format).toEqual('content')

145 145

expect(ref.type).toEqual('blob')

146 146

expect(ref.oid).toEqual('5264f23285d8be3ce45f95c102001ffa1d5391d3')

147 -

expect(ref.object.toString('hex')).toMatchSnapshot()

147 +

expect(Buffer.from(ref.object).toString('hex')).toMatchSnapshot()

148 148

})

149 149

it('with simple filepath to tree', async () => {

150 150

// Setup

Original file line number Diff line number Diff line change

@@ -55,23 +55,25 @@ describe('walk', () => {

55 55

oid: await workdir.oid(),

56 56

content:

57 57

(await workdir.content()) &&

58 -

(await workdir.content()).toString('utf8'),

58 +

Buffer.from(await workdir.content()).toString('utf8'),

59 59

hasStat: !!(await workdir.stat())

60 60

},

61 61

tree && {

62 62

type: await tree.type(),

63 63

mode: await tree.mode(),

64 64

oid: await tree.oid(),

65 65

content:

66 -

(await tree.content()) && (await tree.content()).toString('utf8'),

66 +

(await tree.content()) &&

67 +

Buffer.from(await tree.content()).toString('utf8'),

67 68

hasStat: !!(await tree.stat())

68 69

},

69 70

stage && {

70 71

type: await stage.type(),

71 72

mode: await stage.mode(),

72 73

oid: await stage.oid(),

73 74

content:

74 -

(await stage.content()) && (await stage.content()).toString('utf8'),

75 +

(await stage.content()) &&

76 +

Buffer.from(await stage.content()).toString('utf8'),

75 77

hasStat: !!(await stage.stat())

76 78

}

77 79

]

Original file line number Diff line number Diff line change

@@ -6,7 +6,7 @@ import { hashObject } from '../storage/hashObject.js'

6 6

* @typedef {object} HashBlobResult - The object returned has the following schema:

7 7

* @property {string} oid - The SHA-1 object id

8 8

* @property {'blob'} type - The type of the object

9 -

* @property {Buffer} object - The wrapped git object (the thing that is hashed)

9 +

* @property {Uint8Array} object - The wrapped git object (the thing that is hashed)

10 10

* @property {'wrapped'} format - The format of the object

11 11

*

12 12

*/

@@ -16,9 +16,9 @@ import { hashObject } from '../storage/hashObject.js'

16 16

*

17 17

* @param {object} args

18 18

* @param {string} [args.core = 'default'] - The plugin core identifier to use for plugin injection

19 -

* @param {Buffer|string} args.object - The object to write. If `object` is a String then it will be converted to a Buffer using UTF-8 encoding.

19 +

* @param {Uint8Array|string} args.object - The object to write. If `object` is a String then it will be converted to a Uint8Array using UTF-8 encoding.

20 20

*

21 -

* @returns {Promise<{HashBlobResult}>} Resolves successfully with the SHA-1 object id and the wrapped object Buffer.

21 +

* @returns {Promise<{HashBlobResult}>} Resolves successfully with the SHA-1 object id and the wrapped object Uint8Array.

22 22

* @see HashBlobResult

23 23

*

24 24

* @example

@@ -37,6 +37,8 @@ export async function hashBlob ({ core = 'default', object }) {

37 37

// Convert object to buffer

38 38

if (typeof object === 'string') {

39 39

object = Buffer.from(object, 'utf8')

40 +

} else {

41 +

object = Buffer.from(object)

40 42

}

41 43 42 44

const type = 'blob'

@@ -45,7 +47,7 @@ export async function hashBlob ({ core = 'default', object }) {

45 47

format: 'content',

46 48

object

47 49

})

48 -

return { oid, type, object: _object, format: 'wrapped' }

50 +

return { oid, type, object: new Uint8Array(_object), format: 'wrapped' }

49 51

} catch (err) {

50 52

err.caller = 'git.hashBlob'

51 53

throw err

Original file line number Diff line number Diff line change

@@ -10,7 +10,7 @@ import { pack } from './pack'

10 10

*

11 11

* @typedef {Object} PackObjectsResponse The packObjects command returns an object with two properties:

12 12

* @property {string} filename - The suggested filename for the packfile if you want to save it to disk somewhere. It includes the packfile SHA.

13 -

* @property {Buffer} [packfile] - The packfile contents. Not present if `write` parameter was true, in which case the packfile was written straight to disk.

13 +

* @property {Uint8Array} [packfile] - The packfile contents. Not present if `write` parameter was true, in which case the packfile was written straight to disk.

14 14

*/

15 15 16 16

/**

@@ -56,7 +56,7 @@ export async function packObjects ({

56 56

}

57 57

return {

58 58

filename,

59 -

packfile

59 +

packfile: new Uint8Array(packfile)

60 60

}

61 61

} catch (err) {

62 62

err.caller = 'git.packObjects'

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4