Skip to content

Instantly share code, notes, and snippets.

@janl
Created April 11, 2019 19:59
Show Gist options
  • Save janl/2bb1bf9769858291312f2b7dc2e5ea6b to your computer and use it in GitHub Desktop.
Save janl/2bb1bf9769858291312f2b7dc2e5ea6b to your computer and use it in GitHub Desktop.
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index c6404b04d..1a58b95ea 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -1409,6 +1409,16 @@ couch_doc_open(Db, DocId, Rev, Options0) ->
% Attachment request handlers
+is_tgz(FileName) ->
+ case config:get_boolean("couchdb", "tiny_npm", false) of
+ true ->
+ case lists:suffix(".tgz", FileName) of
+ true -> true;
+ _ -> false
+ end;
+ _False -> false
+ end.
+
db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNameParts) ->
FileName = list_to_binary(mochiweb_util:join(lists:map(fun binary_to_list/1,
FileNameParts),"/")),
@@ -1537,10 +1547,18 @@ db_attachment_req(#httpd{method=Method, user_ctx=Ctx}=Req, Db, DocId, FileNamePa
undefined -> undefined;
Length -> list_to_integer(Length)
end,
- ContentEnc = string:to_lower(string:strip(
- couch_httpd:header_value(Req, "Content-Encoding", "identity")
- )),
+ ContentEnc = case is_tgz(FileName) of
+ true ->
+ "tgz";
+ _False ->
+ string:to_lower(string:strip(
+ couch_httpd:header_value(Req, "Content-Encoding", "identity")
+ ))
+ end,
+
Encoding = case ContentEnc of
+ "tgz" ->
+ tgz;
"identity" ->
identity;
"gzip" ->
diff --git a/src/couch/src/couch_stream.erl b/src/couch/src/couch_stream.erl
index 033562932..b203ab61a 100644
--- a/src/couch/src/couch_stream.erl
+++ b/src/couch/src/couch_stream.erl
@@ -107,6 +107,7 @@ foldl(Engine, Md5, UserFun, UserAcc) ->
foldl_decode(Engine, Md5, Enc, UserFun, UserAcc1) ->
{DecDataFun, DecEndFun} = case Enc of
gzip -> ungzip_init();
+ tgz -> gzip_init({[]});
identity -> identity_enc_dec_funs()
end,
InitAcc = {DecDataFun, UserFun, UserAcc1},
@@ -196,6 +197,7 @@ init({Engine, OpenerPid, OpenerPriority, Options}) ->
{EncodingFun, EndEncodingFun} =
case couch_util:get_value(encoding, Options, identity) of
identity -> identity_enc_dec_funs();
+ tgz -> ungzip_init();
gzip -> gzip_init(Options)
end,
{ok, #stream{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment