Method: AudioFile#write
- Defined in:
- lib/id3/audiofile.rb
#write(*filename) ⇒ Object
write
write the AudioFile to file, including any ID3-
We keep backups if we write to a specific filename
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/id3/audiofile.rb', line 105 def write(*filename) backups = false if filename.size == 0 # this is an Array!! filename = @filename backups = true # keep backups if we write to a specific filename else filename = filename[0] backups = false end tf = Tempfile.new( @basename ) tmpname = tf.path # write ID3v2 tag: if @tagID3v2 tf.write( @tagID3v2.dump ) end # write Audio Data: tf.write( audio ) # reads audio from file if nil # write ID3v1 tag: if @tagID3v1 tf.write( @tagID3v1.dump ) end tf.close # now some logic about moving the tempfile and replacing the original bakname = filename + '.bak' move(filename, bakname) if backups && FileTest.exists?(filename) && ! FileTest.exists?(bakname) move(tmpname, filename) tf.close(true) # write md5sum sha1sum files: writeMD5sum if @audioMD5sum writeSHA1sum if @audioSHA1sum end |