Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

demo code of get in readme is wrong? #2933

Closed
bluelovers opened this issue Mar 21, 2020 · 1 comment
Closed

demo code of get in readme is wrong? #2933

bluelovers opened this issue Mar 21, 2020 · 1 comment

Comments

@bluelovers
Copy link
Contributor

i use cid from readme

QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF

but get a error

TypeError: Cannot read property 'Symbol(Symbol.asyncIterator)' of undefined

when i print it, only get

{ path: 'QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF' }

code

export async function get(ipfs: IIPFSFileApi)
{
	const cid = 'QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF'

	let success = false;
	let error: Error;

	const startTime = Date.now();

	await Promise.resolve()
		.then(async () => {
			for await (const file of ipfs.get(cid)) {
				console.dir(file)

				const content = new BufferList()
				for await (const chunk of file.content) {
					content.append(chunk)
				}

				console.log(content.toString())
			}
		})
		.catch(e => {
			error = e
		})
	;

	return {
		success,
		spendTime: Date.now() - startTime,
		error,
	}
}
@achingbrain
Copy link
Member

Thanks for submitting a PR to improve the docs!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants