Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 3130b8f

Browse files
committed
Import ipfs.add tests from js-ipfs, js-ipfs-api.
Also replaces the old javascript test data with Project Gutenberg prose. Also returns object wrapping path+node on ipfs.files.add.
1 parent 80edc88 commit 3130b8f

14 files changed

+13708
-7
lines changed

README.md

+17-6
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,26 @@ Where `data` may be
7979

8080
`callback` must follow `function (err, res) {}` signature, where `err` is an
8181
error if the operation was not successful. `res` will be an array of
82-
[DAGNode][]s.
82+
83+
```js
84+
{
85+
path: '/tmp/myfile.txt',
86+
node: DAGNode
87+
}
88+
```
8389

8490
If no `callback` is passed, a promise is returned.
8591

92+
Example:
8693
```js
8794
var files = [
8895
{
8996
path: '/tmp/myfile.txt',
90-
content: fs.createReadStream('/tmp/myfile.txt')
97+
content: (Buffer or Readable stream)
9198
}
9299
]
93-
ipfs.files.add(files, function (err, dagNodes) {
94-
// 'res' will be an array of DAGNodes
100+
ipfs.files.add(files, function (err, files) {
101+
// 'files' will be an array of objects
95102
})
96103
```
97104

@@ -122,8 +129,12 @@ If no `callback` is passed, a promise is returned.
122129

123130
```js
124131
ipfs.files.createAddStream(function (err, stream) {
125-
stream.on('data', function (dagNode) {
126-
// ...
132+
stream.on('data', function (file) {
133+
// 'file' will be of the form
134+
// {
135+
// path: '/tmp/myfile.txt',
136+
// node: DAGNode
137+
// }
127138
})
128139

129140
stream.write({path: <path to file>, content: <buffer or readable stream>})

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
},
2929
"homepage": "https://github.com/ipfs/interface-ipfs-core#readme",
3030
"dependencies": {
31+
"bl": "^1.1.2",
3132
"bs58": "^3.0.0",
3233
"chai": "^3.5.0",
33-
"ipfs-merkle-dag": "^0.6.0"
34+
"detect-node": "^2.0.3",
35+
"ipfs-merkle-dag": "^0.6.0",
36+
"readable-stream": "1.1.13"
3437
},
3538
"devDependencies": {
3639
"aegir": "^3.0.4"

test/data/15mb.random

14.3 MB
Binary file not shown.

test/data/test-folder/alice.txt

+283
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
CHAPTER XII. Alice's Evidence
2+
3+
4+
'Here!' cried Alice, quite forgetting in the flurry of the moment how
5+
large she had grown in the last few minutes, and she jumped up in such
6+
a hurry that she tipped over the jury-box with the edge of her skirt,
7+
upsetting all the jurymen on to the heads of the crowd below, and there
8+
they lay sprawling about, reminding her very much of a globe of goldfish
9+
she had accidentally upset the week before.
10+
11+
'Oh, I BEG your pardon!' she exclaimed in a tone of great dismay, and
12+
began picking them up again as quickly as she could, for the accident of
13+
the goldfish kept running in her head, and she had a vague sort of idea
14+
that they must be collected at once and put back into the jury-box, or
15+
they would die.
16+
17+
'The trial cannot proceed,' said the King in a very grave voice, 'until
18+
all the jurymen are back in their proper places--ALL,' he repeated with
19+
great emphasis, looking hard at Alice as he said do.
20+
21+
Alice looked at the jury-box, and saw that, in her haste, she had put
22+
the Lizard in head downwards, and the poor little thing was waving its
23+
tail about in a melancholy way, being quite unable to move. She soon got
24+
it out again, and put it right; 'not that it signifies much,' she said
25+
to herself; 'I should think it would be QUITE as much use in the trial
26+
one way up as the other.'
27+
28+
As soon as the jury had a little recovered from the shock of being
29+
upset, and their slates and pencils had been found and handed back to
30+
them, they set to work very diligently to write out a history of the
31+
accident, all except the Lizard, who seemed too much overcome to do
32+
anything but sit with its mouth open, gazing up into the roof of the
33+
court.
34+
35+
'What do you know about this business?' the King said to Alice.
36+
37+
'Nothing,' said Alice.
38+
39+
'Nothing WHATEVER?' persisted the King.
40+
41+
'Nothing whatever,' said Alice.
42+
43+
'That's very important,' the King said, turning to the jury. They were
44+
just beginning to write this down on their slates, when the White Rabbit
45+
interrupted: 'UNimportant, your Majesty means, of course,' he said in a
46+
very respectful tone, but frowning and making faces at him as he spoke.
47+
48+
'UNimportant, of course, I meant,' the King hastily said, and went on
49+
to himself in an undertone,
50+
51+
'important--unimportant--unimportant--important--' as if he were trying
52+
which word sounded best.
53+
54+
Some of the jury wrote it down 'important,' and some 'unimportant.'
55+
Alice could see this, as she was near enough to look over their slates;
56+
'but it doesn't matter a bit,' she thought to herself.
57+
58+
At this moment the King, who had been for some time busily writing in
59+
his note-book, cackled out 'Silence!' and read out from his book, 'Rule
60+
Forty-two. ALL PERSONS MORE THAN A MILE HIGH TO LEAVE THE COURT.'
61+
62+
Everybody looked at Alice.
63+
64+
'I'M not a mile high,' said Alice.
65+
66+
'You are,' said the King.
67+
68+
'Nearly two miles high,' added the Queen.
69+
70+
'Well, I shan't go, at any rate,' said Alice: 'besides, that's not a
71+
regular rule: you invented it just now.'
72+
73+
'It's the oldest rule in the book,' said the King.
74+
75+
'Then it ought to be Number One,' said Alice.
76+
77+
The King turned pale, and shut his note-book hastily. 'Consider your
78+
verdict,' he said to the jury, in a low, trembling voice.
79+
80+
'There's more evidence to come yet, please your Majesty,' said the White
81+
Rabbit, jumping up in a great hurry; 'this paper has just been picked
82+
up.'
83+
84+
'What's in it?' said the Queen.
85+
86+
'I haven't opened it yet,' said the White Rabbit, 'but it seems to be a
87+
letter, written by the prisoner to--to somebody.'
88+
89+
'It must have been that,' said the King, 'unless it was written to
90+
nobody, which isn't usual, you know.'
91+
92+
'Who is it directed to?' said one of the jurymen.
93+
94+
'It isn't directed at all,' said the White Rabbit; 'in fact, there's
95+
nothing written on the OUTSIDE.' He unfolded the paper as he spoke, and
96+
added 'It isn't a letter, after all: it's a set of verses.'
97+
98+
'Are they in the prisoner's handwriting?' asked another of the jurymen.
99+
100+
'No, they're not,' said the White Rabbit, 'and that's the queerest thing
101+
about it.' (The jury all looked puzzled.)
102+
103+
'He must have imitated somebody else's hand,' said the King. (The jury
104+
all brightened up again.)
105+
106+
'Please your Majesty,' said the Knave, 'I didn't write it, and they
107+
can't prove I did: there's no name signed at the end.'
108+
109+
'If you didn't sign it,' said the King, 'that only makes the matter
110+
worse. You MUST have meant some mischief, or else you'd have signed your
111+
name like an honest man.'
112+
113+
There was a general clapping of hands at this: it was the first really
114+
clever thing the King had said that day.
115+
116+
'That PROVES his guilt,' said the Queen.
117+
118+
'It proves nothing of the sort!' said Alice. 'Why, you don't even know
119+
what they're about!'
120+
121+
'Read them,' said the King.
122+
123+
The White Rabbit put on his spectacles. 'Where shall I begin, please
124+
your Majesty?' he asked.
125+
126+
'Begin at the beginning,' the King said gravely, 'and go on till you
127+
come to the end: then stop.'
128+
129+
These were the verses the White Rabbit read:--
130+
131+
'They told me you had been to her,
132+
And mentioned me to him:
133+
She gave me a good character,
134+
But said I could not swim.
135+
136+
He sent them word I had not gone
137+
(We know it to be true):
138+
If she should push the matter on,
139+
What would become of you?
140+
141+
I gave her one, they gave him two,
142+
You gave us three or more;
143+
They all returned from him to you,
144+
Though they were mine before.
145+
146+
If I or she should chance to be
147+
Involved in this affair,
148+
He trusts to you to set them free,
149+
Exactly as we were.
150+
151+
My notion was that you had been
152+
(Before she had this fit)
153+
An obstacle that came between
154+
Him, and ourselves, and it.
155+
156+
Don't let him know she liked them best,
157+
For this must ever be
158+
A secret, kept from all the rest,
159+
Between yourself and me.'
160+
161+
'That's the most important piece of evidence we've heard yet,' said the
162+
King, rubbing his hands; 'so now let the jury--'
163+
164+
'If any one of them can explain it,' said Alice, (she had grown so large
165+
in the last few minutes that she wasn't a bit afraid of interrupting
166+
him,) 'I'll give him sixpence. _I_ don't believe there's an atom of
167+
meaning in it.'
168+
169+
The jury all wrote down on their slates, 'SHE doesn't believe there's an
170+
atom of meaning in it,' but none of them attempted to explain the paper.
171+
172+
'If there's no meaning in it,' said the King, 'that saves a world of
173+
trouble, you know, as we needn't try to find any. And yet I don't know,'
174+
he went on, spreading out the verses on his knee, and looking at them
175+
with one eye; 'I seem to see some meaning in them, after all. "--SAID
176+
I COULD NOT SWIM--" you can't swim, can you?' he added, turning to the
177+
Knave.
178+
179+
The Knave shook his head sadly. 'Do I look like it?' he said. (Which he
180+
certainly did NOT, being made entirely of cardboard.)
181+
182+
'All right, so far,' said the King, and he went on muttering over
183+
the verses to himself: '"WE KNOW IT TO BE TRUE--" that's the jury, of
184+
course--"I GAVE HER ONE, THEY GAVE HIM TWO--" why, that must be what he
185+
did with the tarts, you know--'
186+
187+
'But, it goes on "THEY ALL RETURNED FROM HIM TO YOU,"' said Alice.
188+
189+
'Why, there they are!' said the King triumphantly, pointing to the tarts
190+
on the table. 'Nothing can be clearer than THAT. Then again--"BEFORE SHE
191+
HAD THIS FIT--" you never had fits, my dear, I think?' he said to the
192+
Queen.
193+
194+
'Never!' said the Queen furiously, throwing an inkstand at the Lizard
195+
as she spoke. (The unfortunate little Bill had left off writing on his
196+
slate with one finger, as he found it made no mark; but he now hastily
197+
began again, using the ink, that was trickling down his face, as long as
198+
it lasted.)
199+
200+
'Then the words don't FIT you,' said the King, looking round the court
201+
with a smile. There was a dead silence.
202+
203+
'It's a pun!' the King added in an offended tone, and everybody laughed,
204+
'Let the jury consider their verdict,' the King said, for about the
205+
twentieth time that day.
206+
207+
'No, no!' said the Queen. 'Sentence first--verdict afterwards.'
208+
209+
'Stuff and nonsense!' said Alice loudly. 'The idea of having the
210+
sentence first!'
211+
212+
'Hold your tongue!' said the Queen, turning purple.
213+
214+
'I won't!' said Alice.
215+
216+
'Off with her head!' the Queen shouted at the top of her voice. Nobody
217+
moved.
218+
219+
'Who cares for you?' said Alice, (she had grown to her full size by this
220+
time.) 'You're nothing but a pack of cards!'
221+
222+
At this the whole pack rose up into the air, and came flying down upon
223+
her: she gave a little scream, half of fright and half of anger, and
224+
tried to beat them off, and found herself lying on the bank, with her
225+
head in the lap of her sister, who was gently brushing away some dead
226+
leaves that had fluttered down from the trees upon her face.
227+
228+
'Wake up, Alice dear!' said her sister; 'Why, what a long sleep you've
229+
had!'
230+
231+
'Oh, I've had such a curious dream!' said Alice, and she told her
232+
sister, as well as she could remember them, all these strange Adventures
233+
of hers that you have just been reading about; and when she had
234+
finished, her sister kissed her, and said, 'It WAS a curious dream,
235+
dear, certainly: but now run in to your tea; it's getting late.' So
236+
Alice got up and ran off, thinking while she ran, as well she might,
237+
what a wonderful dream it had been.
238+
239+
But her sister sat still just as she left her, leaning her head on her
240+
hand, watching the setting sun, and thinking of little Alice and all her
241+
wonderful Adventures, till she too began dreaming after a fashion, and
242+
this was her dream:--
243+
244+
First, she dreamed of little Alice herself, and once again the tiny
245+
hands were clasped upon her knee, and the bright eager eyes were looking
246+
up into hers--she could hear the very tones of her voice, and see that
247+
queer little toss of her head to keep back the wandering hair that
248+
WOULD always get into her eyes--and still as she listened, or seemed to
249+
listen, the whole place around her became alive with the strange creatures
250+
of her little sister's dream.
251+
252+
The long grass rustled at her feet as the White Rabbit hurried by--the
253+
frightened Mouse splashed his way through the neighbouring pool--she
254+
could hear the rattle of the teacups as the March Hare and his friends
255+
shared their never-ending meal, and the shrill voice of the Queen
256+
ordering off her unfortunate guests to execution--once more the pig-baby
257+
was sneezing on the Duchess's knee, while plates and dishes crashed
258+
around it--once more the shriek of the Gryphon, the squeaking of the
259+
Lizard's slate-pencil, and the choking of the suppressed guinea-pigs,
260+
filled the air, mixed up with the distant sobs of the miserable Mock
261+
Turtle.
262+
263+
So she sat on, with closed eyes, and half believed herself in
264+
Wonderland, though she knew she had but to open them again, and all
265+
would change to dull reality--the grass would be only rustling in the
266+
wind, and the pool rippling to the waving of the reeds--the rattling
267+
teacups would change to tinkling sheep-bells, and the Queen's shrill
268+
cries to the voice of the shepherd boy--and the sneeze of the baby, the
269+
shriek of the Gryphon, and all the other queer noises, would change (she
270+
knew) to the confused clamour of the busy farm-yard--while the lowing
271+
of the cattle in the distance would take the place of the Mock Turtle's
272+
heavy sobs.
273+
274+
Lastly, she pictured to herself how this same little sister of hers
275+
would, in the after-time, be herself a grown woman; and how she would
276+
keep, through all her riper years, the simple and loving heart of her
277+
childhood: and how she would gather about her other little children, and
278+
make THEIR eyes bright and eager with many a strange tale, perhaps even
279+
with the dream of Wonderland of long ago: and how she would feel with
280+
all their simple sorrows, and find a pleasure in all their simple joys,
281+
remembering her own child-life, and the happy summer days.
282+
283+
THE END

test/data/test-folder/files/hello.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello

test/data/test-folder/files/ipfs.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IPFS

test/data/test-folder/hello-link

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
files/hello.txt

0 commit comments

Comments
 (0)