tar: compress text stdin and stdout [duplicate]











up vote
1
down vote

favorite













This question already has an answer here:




  • Is it possible to make a .tar.gz file directly from stdin? Or, I need to tar together already gzipped files

    4 answers




Using tar, is it possible to compress stdin text and have the compressed data appear in stdout? Example:



$ echo "test" | tar c - 
<compressed blob here>


I'm using macOS Mojave.










share|improve this question







New contributor




user322355 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by Filipe Brandenburger, Kusalananda linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 at 18:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    1
    down vote

    favorite













    This question already has an answer here:




    • Is it possible to make a .tar.gz file directly from stdin? Or, I need to tar together already gzipped files

      4 answers




    Using tar, is it possible to compress stdin text and have the compressed data appear in stdout? Example:



    $ echo "test" | tar c - 
    <compressed blob here>


    I'm using macOS Mojave.










    share|improve this question







    New contributor




    user322355 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.











    marked as duplicate by Filipe Brandenburger, Kusalananda linux
    Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 22 at 18:23


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite












      This question already has an answer here:




      • Is it possible to make a .tar.gz file directly from stdin? Or, I need to tar together already gzipped files

        4 answers




      Using tar, is it possible to compress stdin text and have the compressed data appear in stdout? Example:



      $ echo "test" | tar c - 
      <compressed blob here>


      I'm using macOS Mojave.










      share|improve this question







      New contributor




      user322355 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      This question already has an answer here:




      • Is it possible to make a .tar.gz file directly from stdin? Or, I need to tar together already gzipped files

        4 answers




      Using tar, is it possible to compress stdin text and have the compressed data appear in stdout? Example:



      $ echo "test" | tar c - 
      <compressed blob here>


      I'm using macOS Mojave.





      This question already has an answer here:




      • Is it possible to make a .tar.gz file directly from stdin? Or, I need to tar together already gzipped files

        4 answers








      linux terminal osx tar compression






      share|improve this question







      New contributor




      user322355 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      user322355 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      user322355 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 22 at 18:09









      user322355

      82




      82




      New contributor




      user322355 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user322355 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user322355 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      marked as duplicate by Filipe Brandenburger, Kusalananda linux
      Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 22 at 18:23


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Filipe Brandenburger, Kusalananda linux
      Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 22 at 18:23


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          In short, no it's not possible to do that without storing the whole contents of stdin into a file or temporary file (e.g. in memory.)



          This is a limitation of the tar file format itself, since before storing the file contents, tar stores a descriptor for the file, including file name, etc. and also the file size. So tar needs to know what is the size of the file before storing it. When reading from stdin, tar can't know the size of the contents, unless it reads all of them, in which case it'll need to store them somewhere, in order to store those contents in the tarball itself.



          See also "Is it possible to make a .tar.gz file directly from stdin? Or, I need to tar together already gzipped files." One of the answers lists a way to store the contents of the file first, then seek back and update the file descriptor to write the actual size of the contents. But that requires the ability to seek on the output file, which is typically not the case if you're writing to stdout...



          In short, you need to write your input to a temporary file, in order to add it to a tarball.






          share|improve this answer




























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            In short, no it's not possible to do that without storing the whole contents of stdin into a file or temporary file (e.g. in memory.)



            This is a limitation of the tar file format itself, since before storing the file contents, tar stores a descriptor for the file, including file name, etc. and also the file size. So tar needs to know what is the size of the file before storing it. When reading from stdin, tar can't know the size of the contents, unless it reads all of them, in which case it'll need to store them somewhere, in order to store those contents in the tarball itself.



            See also "Is it possible to make a .tar.gz file directly from stdin? Or, I need to tar together already gzipped files." One of the answers lists a way to store the contents of the file first, then seek back and update the file descriptor to write the actual size of the contents. But that requires the ability to seek on the output file, which is typically not the case if you're writing to stdout...



            In short, you need to write your input to a temporary file, in order to add it to a tarball.






            share|improve this answer

























              up vote
              1
              down vote



              accepted










              In short, no it's not possible to do that without storing the whole contents of stdin into a file or temporary file (e.g. in memory.)



              This is a limitation of the tar file format itself, since before storing the file contents, tar stores a descriptor for the file, including file name, etc. and also the file size. So tar needs to know what is the size of the file before storing it. When reading from stdin, tar can't know the size of the contents, unless it reads all of them, in which case it'll need to store them somewhere, in order to store those contents in the tarball itself.



              See also "Is it possible to make a .tar.gz file directly from stdin? Or, I need to tar together already gzipped files." One of the answers lists a way to store the contents of the file first, then seek back and update the file descriptor to write the actual size of the contents. But that requires the ability to seek on the output file, which is typically not the case if you're writing to stdout...



              In short, you need to write your input to a temporary file, in order to add it to a tarball.






              share|improve this answer























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                In short, no it's not possible to do that without storing the whole contents of stdin into a file or temporary file (e.g. in memory.)



                This is a limitation of the tar file format itself, since before storing the file contents, tar stores a descriptor for the file, including file name, etc. and also the file size. So tar needs to know what is the size of the file before storing it. When reading from stdin, tar can't know the size of the contents, unless it reads all of them, in which case it'll need to store them somewhere, in order to store those contents in the tarball itself.



                See also "Is it possible to make a .tar.gz file directly from stdin? Or, I need to tar together already gzipped files." One of the answers lists a way to store the contents of the file first, then seek back and update the file descriptor to write the actual size of the contents. But that requires the ability to seek on the output file, which is typically not the case if you're writing to stdout...



                In short, you need to write your input to a temporary file, in order to add it to a tarball.






                share|improve this answer












                In short, no it's not possible to do that without storing the whole contents of stdin into a file or temporary file (e.g. in memory.)



                This is a limitation of the tar file format itself, since before storing the file contents, tar stores a descriptor for the file, including file name, etc. and also the file size. So tar needs to know what is the size of the file before storing it. When reading from stdin, tar can't know the size of the contents, unless it reads all of them, in which case it'll need to store them somewhere, in order to store those contents in the tarball itself.



                See also "Is it possible to make a .tar.gz file directly from stdin? Or, I need to tar together already gzipped files." One of the answers lists a way to store the contents of the file first, then seek back and update the file descriptor to write the actual size of the contents. But that requires the ability to seek on the output file, which is typically not the case if you're writing to stdout...



                In short, you need to write your input to a temporary file, in order to add it to a tarball.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 at 18:30









                Filipe Brandenburger

                6,3721725




                6,3721725















                    Popular posts from this blog

                    Accessing regular linux commands in Huawei's Dopra Linux

                    Can't connect RFCOMM socket: Host is down

                    Kernel panic - not syncing: Fatal Exception in Interrupt