示例#1
0
        public virtual Uri Write(Stream source, Uri sink)
        {
            if (sink == null)
            {
                throw new ArgumentException("Uri must not be null");
            }

            if (IoMode.HasFlag(IO.IoMode.Write) && sink.IsFile)
            {
                var filename   = IoUtils.UriToFileName(sink);
                var file       = new FileStream(filename, FileMode.Create);
                var target     = new BufferedStream(file);
                var bufferSize = 1024 * 1024;
                var buffer     = new byte[bufferSize];
                var oldPos     = source.Position;
                int readByte   = 0;
                int position   = 0;

                long endpos = source.Length - 1;
                while (position < endpos)
                {
                    readByte = source.Read(buffer, 0, bufferSize);
                    target.Write(buffer, 0, readByte);
                    position += readByte;
                }

                target.Flush();
                target.Close();
                source.Position = oldPos;
            }
            return(sink);
        }
示例#2
0
        // SetIoMode(nn::ssl::sf::IoMode)
        public ResultCode SetIoMode(ServiceCtx context)
        {
            IoMode ioMode = (IoMode)context.RequestData.ReadUInt32();

            Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { ioMode });

            return(ResultCode.Success);
        }
示例#3
0
 public ISslConnection(ulong processId, SslVersion sslVersion)
 {
     _processId        = processId;
     _sslVersion       = sslVersion;
     _ioMode           = IoMode.Blocking;
     _sessionCacheMode = SessionCacheMode.None;
     _verifyOption     = VerifyOption.PeerCa | VerifyOption.HostName;
 }
示例#4
0
        public virtual Stream Read(Uri uri)
        {
            var result = default(Stream);

            if (IoMode.HasFlag(IO.IoMode.Read) && uri.IsFile)
            {
                var filename = IoUtils.UriToFileName(uri);
                var file     = new FileStream(filename, FileMode.Open);
            }
            return(result);
        }
示例#5
0
        internal static JobIo ForFile(Context c, string path, IoMode mode)
        {
            var cpath = GCHandle.Alloc(Encoding.ASCII.GetBytes(path + char.MinValue), GCHandleType.Pinned);

            try
            {
                return(new JobIo(c,
                                 NativeMethods.imageflow_io_create_for_file(c.Pointer, mode,
                                                                            cpath.AddrOfPinnedObject(),
                                                                            CleanupWith.Context)));
            } finally{
                cpath.Free();
            }
        }
示例#6
0
        // SetIoMode(nn::ssl::sf::IoMode)
        public ResultCode SetIoMode(ServiceCtx context)
        {
            if (_connection == null)
            {
                return(ResultCode.NoSocket);
            }

            _ioMode = (IoMode)context.RequestData.ReadUInt32();

            _connection.Socket.Blocking = _ioMode == IoMode.Blocking;

            Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { _ioMode });

            return(ResultCode.Success);
        }
示例#7
0
        public byte[] ToBytes(IoMode ioMode)
        {
            unsafe
            {
                const int   maxBufSize = 1024;
                Span <byte> res        = stackalloc byte[maxBufSize];
                ulong       len;
                fixed(G2 *ptr = &this)
                fixed(byte *resPtr = res)
                {
                    len = MclBls12381.Imports.MclBnG2GetStr.Value(resPtr, maxBufSize, ptr, (int)ioMode);
                }

                return(res.Slice(0, (int)len).ToArray());
            }
        }
示例#8
0
        public byte[] ToBytes(IoMode ioMode)
        {
            unsafe
            {
                const int   maxSize = 1024;
                Span <byte> buf     = stackalloc byte[maxSize];
                fixed(Fr *ptr = &this)
                fixed(byte *bufPtr = buf)
                {
                    var size = MclBls12381.Imports.MclBnFrGetStr.Value(bufPtr, maxSize, ptr, (int)ioMode);

                    if (size == 0 || size > 1024)
                    {
                        throw new InvalidOperationException("mclBnFr_getStr failed to serialize Fr");
                    }
                    return(buf.Slice(0, (int)size).ToArray());
                }
            }
        }
示例#9
0
        public virtual Content <Stream> Read(Uri source, Content <Stream> sink)
        {
            var result = default(Content <Stream>);

            if (IoMode.HasFlag(IO.IoMode.Read) && source.IsFile)
            {
                var filename = IoUtils.UriToFileName(source);
                var file     = new FileStream(filename, FileMode.Open);

                result = Read(file, Detector.Use(file));

                // test if there is a provider with file's extension:
                if (result == null)
                {
                    var info = Detector.Find(Path.GetExtension(filename).Replace(".", ""));
                    if (info.Magics == null || info.Magics.Length == 0)
                    {
                        result = Read(file, info);
                    }
                }

                if (result != null)
                {
                    if (result.Source == null)
                    {
                        result.Source = source.AbsoluteUri;
                    }
                    if (result.Description == null)
                    {
                        result.Description = source.Segments[source.Segments.Length - 1];
                    }
                }
                else
                {
                    file.Close();
                }
            }
            return(result);
        }
示例#10
0
 public static extern JobIoPointer imageflow_io_create_for_file(ContextPointer context, IoMode mode, [MarshalAs(UnmanagedType.LPStr)] string filename, CleanupWith cleanup);
示例#11
0
 public static extern IntPtr imageflow_io_create_for_file(IntPtr context, IoMode mode,
                                                          IntPtr filename, CleanupWith cleanup);
示例#12
0
 public virtual IContentIo <TSource> FindMime(string mimeType, IoMode mode)
 {
     return(FirstOrDefault(_contentIos.Where(sinkIo => sinkIo.Detector.ContentSpecs.Any(s => s.MimeType == mimeType) && sinkIo.IoMode.HasFlag(mode))));
 }
示例#13
0
 public virtual IContentIo <TSource> Find(TSource stream, IoMode mode)
 {
     return(FirstOrDefault(_contentIos.Where(sinkIo => sinkIo.Supports(stream) && sinkIo.IoMode.HasFlag(mode))));
 }
示例#14
0
 public virtual IContentIo <TSource> Find(long streamType, IoMode mode)
 {
     return(FirstOrDefault(_contentIos.Where(sinkIo => sinkIo.Detector.Supports(streamType) && sinkIo.IoMode.HasFlag(mode))));
 }
示例#15
0
 public virtual IContentIo <TSource> Find(string extension, IoMode mode)
 {
     return(FirstOrDefault(_contentIos.Where(sinkIo => sinkIo.Detector.Supports(extension) && sinkIo.IoMode.HasFlag(mode))));
 }