IsBinary() static private méthode

static private IsBinary ( string filename ) : bool
filename string
Résultat bool
Exemple #1
0
        private void WriteEntryCore(TarEntry sourceEntry, bool recurse)
        {
            string   text     = null;
            string   text2    = sourceEntry.File;
            TarEntry tarEntry = (TarEntry)sourceEntry.Clone();

            if (this.applyUserInfoOverrides)
            {
                tarEntry.GroupId   = this.groupId;
                tarEntry.GroupName = this.groupName;
                tarEntry.UserId    = this.userId;
                tarEntry.UserName  = this.userName;
            }
            this.OnProgressMessageEvent(tarEntry, null);
            if (this.asciiTranslate && !tarEntry.IsDirectory)
            {
                bool flag = !TarArchive.IsBinary(text2);
                if (flag)
                {
                    text = Path.GetTempFileName();
                    using (StreamReader streamReader = File.OpenText(text2))
                    {
                        using (Stream stream = File.Create(text))
                        {
                            for (;;)
                            {
                                string text3 = streamReader.ReadLine();
                                if (text3 == null)
                                {
                                    break;
                                }
                                byte[] bytes = Encoding.ASCII.GetBytes(text3);
                                stream.Write(bytes, 0, bytes.Length);
                                stream.WriteByte(10);
                            }
                            stream.Flush();
                        }
                    }
                    tarEntry.Size = new FileInfo(text).Length;
                    text2         = text;
                }
            }
            string text4 = null;

            if (this.rootPath != null && tarEntry.Name.StartsWith(this.rootPath))
            {
                text4 = tarEntry.Name.Substring(this.rootPath.Length + 1);
            }
            if (this.pathPrefix != null)
            {
                text4 = ((text4 == null) ? (this.pathPrefix + "/" + tarEntry.Name) : (this.pathPrefix + "/" + text4));
            }
            if (text4 != null)
            {
                tarEntry.Name = text4;
            }
            this.tarOut.PutNextEntry(tarEntry);
            if (tarEntry.IsDirectory)
            {
                if (recurse)
                {
                    TarEntry[] directoryEntries = tarEntry.GetDirectoryEntries();
                    for (int i = 0; i < directoryEntries.Length; i++)
                    {
                        this.WriteEntryCore(directoryEntries[i], recurse);
                    }
                    return;
                }
            }
            else
            {
                using (Stream stream2 = File.OpenRead(text2))
                {
                    int    num   = 0;
                    byte[] array = new byte[32768];
                    for (;;)
                    {
                        int num2 = stream2.Read(array, 0, array.Length);
                        if (num2 <= 0)
                        {
                            break;
                        }
                        this.tarOut.Write(array, 0, num2);
                        num += num2;
                    }
                }
                if (text != null && text.Length > 0)
                {
                    File.Delete(text);
                }
                this.tarOut.CloseEntry();
            }
        }
Exemple #2
0
        private void ExtractEntry(string destDir, TarEntry entry)
        {
            this.OnProgressMessageEvent(entry, null);
            string text = entry.Name;

            if (Path.IsPathRooted(text))
            {
                text = text.Substring(Path.GetPathRoot(text).Length);
            }
            text = text.Replace('/', Path.DirectorySeparatorChar);
            string text2 = Path.Combine(destDir, text);

            if (entry.IsDirectory)
            {
                TarArchive.EnsureDirectoryExists(text2);
                return;
            }
            string directoryName = Path.GetDirectoryName(text2);

            TarArchive.EnsureDirectoryExists(directoryName);
            bool     flag     = true;
            FileInfo fileInfo = new FileInfo(text2);

            if (fileInfo.Exists)
            {
                if (this.keepOldFiles)
                {
                    this.OnProgressMessageEvent(entry, "Destination file already exists");
                    flag = false;
                }
                else if ((fileInfo.Attributes & FileAttributes.ReadOnly) != (FileAttributes)0)
                {
                    this.OnProgressMessageEvent(entry, "Destination file already exists, and is read-only");
                    flag = false;
                }
            }
            if (flag)
            {
                bool   flag2  = false;
                Stream stream = File.Create(text2);
                if (this.asciiTranslate)
                {
                    flag2 = !TarArchive.IsBinary(text2);
                }
                StreamWriter streamWriter = null;
                if (flag2)
                {
                    streamWriter = new StreamWriter(stream);
                }
                byte[] array = new byte[32768];
                for (;;)
                {
                    int num = this.tarIn.Read(array, 0, array.Length);
                    if (num <= 0)
                    {
                        break;
                    }
                    if (flag2)
                    {
                        int num2 = 0;
                        for (int i = 0; i < num; i++)
                        {
                            if (array[i] == 10)
                            {
                                string @string = Encoding.ASCII.GetString(array, num2, i - num2);
                                streamWriter.WriteLine(@string);
                                num2 = i + 1;
                            }
                        }
                    }
                    else
                    {
                        stream.Write(array, 0, num);
                    }
                }
                if (flag2)
                {
                    streamWriter.Close();
                    return;
                }
                stream.Close();
            }
        }