Q:

Download to stdout with curl and untar from stdout --- but also create a directory

In Bash I can download a file to stdout with curl, then untar the content:
curl -L http://wordpress.org/latest.tar.gz | tar -zx

I desire that the untar will be made into a directory, and that this directory will be created if it isn't already (thus saving an mkdir operation).
I tried this that failed, to untar into an immediately created directory such as example.com:
curl -L http://wordpress.org/latest.tar.gz | tar -zx -C ${domain}/

The command failed with the error curl: (23) Failed writing body (303 != 1369).
Note: This isn't a permission issue as this is a testing environment in which I work from root.
What's wrong with the command?

A:

The issue is that the directory doesn't exist (see here:
https://unix.stackexchange.com/questions/25311/create-target-directory-when-extracting-tarball).
Note that if you create the directory first, it works just fine:
$ domain=example.com
$ mkdir -p ${domain} && curl -L http://wordpress.org/latest.tar.gz | tar -zx -C ${domain}/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   178  100   178    0     0   2902      0 --:--:-- --:--:-- --:--:--  2918 
100 8601k  100 8601k    0     0  4241k      0  0:00:02  0:00:02 --:--:-- 4472k
$ echo $?
0

