Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: metadata padding #37

Merged
merged 9 commits into from
Sep 22, 2022
Merged

fix: metadata padding #37

merged 9 commits into from
Sep 22, 2022

Conversation

agazso
Copy link
Member

@agazso agazso commented Aug 27, 2022

Fixes #35. Adds a test to verify that the content hash is exactly the same as what Bee generates.

Copy link
Member

@nugaon nugaon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract this logic into a separate createMetadataPadding function, but anyway after correcting the comments below, LGTM.

Though, as the comment says above the inserted padding logic, the encryptDecrypt function should correct the byte length difference. are you sure this change is needed?

Also I get errors locally because of the already fixed content-type for .txt files

src/node.ts Outdated Show resolved Hide resolved
src/node.ts Show resolved Hide resolved
@agazso
Copy link
Member Author

agazso commented Sep 2, 2022

Please review it again. I made the changes you asked for, also I updated to use Bee 1.7.0 with the new bee-factory and bee-js 5.0.0.

@agazso agazso requested a review from nugaon September 2, 2022 14:30
@agazso
Copy link
Member Author

agazso commented Sep 2, 2022

Also fixes #38

Copy link
Member

@nugaon nugaon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the test shows, it is an improvement in order to be compatible with the Bee client, but I commented below, I don't think this is the proper way to pad metadata. It adds new line characters in order to not break the stringified JSON structure on load, but it does not carry any information. The deserializer should handle this in an efficient way as this library did so far. I would create a ticket about it in Bee but to be honest I would prefer more to upgrade to a newer version of mantaray already.

}

const uploadData = async (data: Uint8Array): Promise<string> => {
const result = await bee.uploadData(process.env.BEE_POSTAGE, data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong type for the first parameter, BEE_POSTAGE can be string or undefined instead of string | BatchId.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a function for getting process.env.BEE_POSTAGE that throws error if it is undefined.


const metadataBytesSize = toBigEndianFromUint16(metadataBytes.length)
const metadataBytesSize = toBigEndianFromUint16(metadataBytes.length + padding.length)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any sense to add padding length to the metadataByteSize.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the goal was to replicate the implementation in Bee and this is the exact same thing.

@agazso agazso merged commit 3960498 into master Sep 22, 2022
@agazso agazso deleted the fix/metadata-padding branch September 22, 2022 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Padding is missing when adding metadata
2 participants