Exemplo n.º 1
0
        private static byte[] process_blob_parts(IReadOnlyCollection <BlobPart> blobParts, BlobPropertyBag options)
        {/* Docs: https://w3c.github.io/FileAPI/#process-blob-parts */
            using (MemoryStream Stream = new MemoryStream())
            {
                foreach (var element in blobParts)
                {
                    if (element.data is string)
                    {
                        string s = element.data;
                        if (options.endings == EBlobEnding.Native)
                        {
                            string CorrectEnding = FilterCRLF.CRLF;
                            if (!Environment.NewLine.Equals(FilterCRLF.CRLF, StringComparison.Ordinal))
                            {
                                CorrectEnding = FilterCRLF.LF;
                            }

                            string native_line_ending = StringCommon.Replace(s, false, false,
                                                                             (UnicodeCommon.CHAR_CARRIAGE_RETURN, CorrectEnding),
                                                                             (UnicodeCommon.CHAR_LINE_FEED, CorrectEnding));
                            var encodedBytes = System.Text.Encoding.UTF8.GetBytes(native_line_ending);
                            Stream.Write(encodedBytes, (int)Stream.Position, encodedBytes.Length);
                        }
                    }
                    else if (element.data is ReadOnlyMemory <byte> bytes)
                    {
                        Stream.Write(bytes.ToArray(), (int)Stream.Position, bytes.Length);
                    }
                    else if (element.data is Blob blob)
                    {
                        Stream.Write(blob.data, (int)Stream.Position, (int)blob.size);
                    }
                }

                return(Stream.ToArray());
            }
        }
Exemplo n.º 2
0
 public Blob(IReadOnlyCollection <BlobPart> blobParts, BlobPropertyBag options = null)
 {
     data = process_blob_parts(blobParts, options);
     size = (uint)data.Length;
     type = StringCommon.Transform(options.type.AsMemory(), UnicodeCommon.To_ASCII_Lower_Alpha);
 }