Sometimes, you have these .pkg installer files on macOS. Today, I needed to extract them to see what's inside. Here's how you can do it:

xar -xf MyInstaller.pkg

If there is a file called Payload in there, you need to unpack it again:

cat Payload | gunzip -dc | cpio -i

Inspiration was found on StackOverflow.