Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/couch_att.erl
Original file line number Diff line number Diff line change
Expand Up @@ -438,17 +438,30 @@ digest_from_json(Props) ->


to_json(Att, OutputData, DataToFollow, ShowEncoding) ->
[Name, Data, DiskLen, AttLen, Enc, Type, RevPos, Md5] = fetch(
[ExtStoreID,AttExternalSize, AttExternalMD5] = couch_att:fetch([att_extstore_id,
att_extstore_size,
att_extstore_md5], Att),
[Name, Data, DiskLenTmp, AttLen, Enc, Type, RevPos, Md5] = fetch(
[name, data, disk_len, att_len, encoding, type, revpos, md5], Att
),
case ExtStoreID of
undefined ->
DiskLen = DiskLenTmp,
DigestProp = case base64:encode(Md5) of
<<>> -> [];
Digest -> [{<<"digest">>, <<"md5-", Digest/binary>>}]
end;
_ ->
DiskLen = AttExternalSize,
DigestProp = case AttExternalMD5 of
<<>> -> [];
Digest -> [{<<"digest">>, <<"md5-", Digest/binary>>}]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we not repeat ourself in Digest generation?

end
end,
Props = [
{<<"content_type">>, Type},
{<<"revpos">>, RevPos}
],
DigestProp = case base64:encode(Md5) of
<<>> -> [];
Digest -> [{<<"digest">>, <<"md5-", Digest/binary>>}]
end,
DataProps = if
not OutputData orelse Data == stub ->
[{<<"length">>, DiskLen}, {<<"stub">>, true}];
Expand Down