This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
WIP: feat/blocks #52
Merged
Merged
WIP: feat/blocks #52
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3070fe1
core: block get + test
daviddias 5ffe899
core: block get + test
daviddias 712c690
move block get to use BlockService and Block data struct
daviddias cfd1db2
finish block on js-ipfs-core impl + tests
daviddias b042d74
rebase from master
daviddias 1a28019
Add json loader
fbaiodias aa9fa2c
Merge pull request #56 from xicombd/feat/blocks
daviddias c722d3f
tests passing
daviddias 405a0a2
check
daviddias 8a5d52d
check
daviddias 5e3ca3a
only missing local-storage-blob-store being able to store binary data
daviddias 57f309a
update local-storage-blob-store
daviddias b575bec
skip browser for now
daviddias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ exports.start = callback => { | |
| }) | ||
|
|
||
| server.connection({ | ||
| port: 9000 | ||
| port: 9001 | ||
| }) | ||
|
|
||
| // load routes | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* globals describe, it */ | ||
|
|
||
| 'use strict' | ||
|
|
||
| const expect = require('chai').expect | ||
| const base58 = require('bs58') | ||
| const fs = require('fs') | ||
| const IPFS = require('../../src/ipfs-core') | ||
| const Block = require('ipfs-merkle-dag').Block | ||
|
|
||
| const isNode = !global.window | ||
|
|
||
| const fileA = isNode | ||
| ? fs.readFileSync(process.cwd() + '/tests/repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data') | ||
| : new Buffer(require('raw!./../repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')) | ||
|
|
||
| console.log('=>', fileA) | ||
|
|
||
| describe('block', () => { | ||
| var ipfs | ||
|
|
||
| it('get', done => { | ||
| ipfs = new IPFS() | ||
| const b58mh = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe' | ||
| const mh = new Buffer(base58.decode(b58mh)) | ||
| ipfs.block.get(mh, (err, block) => { | ||
| expect(err).to.not.exist | ||
| const eq = fileA.equals(block.data) | ||
| expect(eq).to.equal(true) | ||
| done() | ||
| }) | ||
| }) | ||
| it('put', done => { | ||
| var b = new Block('random data') | ||
| ipfs.block.put(b, function (err) { | ||
| expect(err).to.not.exist | ||
| ipfs.block.get(b.key, function (err, block) { | ||
| expect(err).to.not.exist | ||
| expect(b.data.equals(block.data)).to.equal(true) | ||
| expect(b.key.equals(block.key)).to.equal(true) | ||
| done() | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| it('rm', done => { | ||
| var b = new Block('I will not last long enough') | ||
| ipfs.block.put(b, function (err) { | ||
| expect(err).to.not.exist | ||
| ipfs.block.get(b.key, function (err, block) { | ||
| expect(err).to.not.exist | ||
| ipfs.block.del(b.key, function (err) { | ||
| expect(err).to.not.exist | ||
| ipfs.block.get(b.key, function (err, block) { | ||
| expect(err).to.exist | ||
| done() | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| it('stat', done => { | ||
| const mh = new Buffer(base58 | ||
| .decode('QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe')) | ||
| ipfs.block.stat(mh, (err, stats) => { | ||
| expect(err).to.not.exist | ||
| expect(stats.Key.equals(mh)).to.equal(true) | ||
| expect(stats.Size).to.equal(309) | ||
| done() | ||
| }) | ||
| }) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bugfound (this took me a bit to figure out :))When using raw-loader, a string is returned with the contents of the file, if the file content was text, it would be ok, but since it is an encoded protobuf, it will add extra encoding data (utf8) adding extra bytes to the content of the Buffer, increasing the size of the Block and by so, failing the test. Need to get another way to load the blocks into localstorage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could work for you? https://github.com/martijnvermaat/binary-loader